From 545fb646ae68b9233c4fe3b5602d413caab02923 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Thu, 28 Sep 2017 10:31:43 +0200 Subject: Add option to force the number of columns --- src/main.cc | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/main.cc') diff --git a/src/main.cc b/src/main.cc index 2b9086a..849b75c 100644 --- a/src/main.cc +++ b/src/main.cc @@ -75,11 +75,11 @@ struct MwmHints { class MonMon : virtual Monitor::Observer, virtual Animator::Observer { public: - explicit MonMon(std::shared_ptr const& looper) + MonMon(std::shared_ptr const& looper, unsigned columns) : looper_(looper), animator_(Animator::create(looper)), connected_(false), depth_(0), black_pixel_(0), screen_(nullptr), max_jobs_(0), jobs_(0), requests_(0), - x_(0), y_(0), w_(0), h_(0), + x_(0), y_(0), w_(0), h_(0), force_columns_(columns), rootpmap_(XCB_ATOM_NONE), desktop_window_(XCB_NONE), desktop_pixmap_(XCB_NONE) { pipe_.open(); @@ -614,7 +614,7 @@ private: auto const pad_x = std::min(9.0, w_ / 20.0), pad_y = pad_x; auto const margin_x = std::min(7.5, w_ / 20.0), margin_y = margin_x; auto y = pad_y; - auto const columns = std::max(1, w_ / h_); + auto const columns = force_columns_ ? force_columns_ : std::max(1, w_ / h_); auto const box_width = (w_ - pad_x) / columns - pad_x; auto const box_height = box_height_ + margin_y * 2; if (!job_pattern_) { @@ -632,7 +632,7 @@ private: } pango_layout_set_width(layout_.get(), (box_width - margin_x * 2) * PANGO_SCALE); - auto col = 0; + unsigned col = 0; for (auto const& machine : machines_) { pango_layout_set_text(layout_.get(), machine.data.name.data(), machine.data.name.size()); @@ -819,6 +819,7 @@ private: x::unique_pixmap pixmap_; int16_t x_, y_; uint16_t w_, h_; + unsigned force_columns_; xcb_atom_t rootpmap_; xcb_window_t desktop_window_; xcb_pixmap_t desktop_pixmap_; @@ -953,6 +954,8 @@ int main(int argc, char** argv) { args->add("titlebar", "create a normal window instead of the default without" " titlebar (or other WM addons)"); args->add("black", "use black background instead of background pixmap"); + args->add("columns", "COLUMNS", "force columns to be COLUMNS instead of" + " calculated from window size"); args->add("help", "display this text and exit."); if (!args->run(argc, argv)) { std::cout << "Try `monmon --help` for usage." << std::endl; @@ -965,6 +968,19 @@ int main(int argc, char** argv) { args->print_help(std::cout); return EXIT_FAILURE; } + unsigned columns = 0; + { + auto tmp = args->arg("columns", nullptr); + if (tmp) { + char* end = nullptr; + errno = 0; + columns = strtoul(tmp, &end, 10); + if (errno || columns == 0 || *end) { + std::cerr << "Invalid value for columns: '" << tmp << "'" << std::endl; + return EXIT_FAILURE; + } + } + } int screen_index; x::shared_connection conn( xcb_connect(args->arg("display", nullptr), &screen_index)); @@ -989,7 +1005,7 @@ int main(int argc, char** argv) { atoms->preload("_MOTIF_WM_HINTS"); atoms->preload("_XROOTPMAP_ID", false); std::shared_ptr ewmh(x::Ewmh::create(conn, screen_index)); - auto monmon = std::make_shared(looper); + auto monmon = std::make_shared(looper, columns); monmon->init(conn, screen, format, atoms, ewmh, 400, 400, args->is_set("titlebar"), args->is_set("black")); monmon->connect(args.get()); -- cgit v1.3