From 341c4e04ffc5572dc02563df914dc65a0a57b9f3 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 27 May 2002 03:12:21 +0000 Subject: [PATCH] mouse wheel support custom titlebar layout --- src/Screen.cc | 12 +++++ src/Window.cc | 131 ++++++++++++++++++++++++++++++++---------------- src/blackbox.cc | 4 ++ src/blackbox.hh | 4 ++ 4 files changed, 108 insertions(+), 43 deletions(-) diff --git a/src/Screen.cc b/src/Screen.cc index 67033a82..919ea9b6 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -1927,6 +1927,18 @@ void BScreen::buttonPressEvent(XButtonEvent *xbutton) { blackbox->checkMenu(); rootmenu->show(); } + // mouse wheel up + } else if (xbutton->button == 4) { + if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1) + changeWorkspaceID(0); + else + changeWorkspaceID(getCurrentWorkspaceID() + 1); + // mouse wheel down + } else if (xbutton->button == 5) { + if (getCurrentWorkspaceID() == 0) + changeWorkspaceID(getWorkspaceCount() - 1); + else + changeWorkspaceID(getCurrentWorkspaceID() - 1); } } diff --git a/src/Window.cc b/src/Window.cc index a4186880..a1be1f7e 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -55,6 +55,7 @@ extern "C" { #include "Workspace.hh" #include "Slit.hh" +using std::string; /* * Initializes the class with default values/the window's set initial values. @@ -649,54 +650,86 @@ void BlackboxWindow::destroyMaximizeButton(void) { void BlackboxWindow::positionButtons(bool redecorate_label) { - unsigned int bw = frame.button_w + frame.bevel_w + 1, - by = frame.bevel_w + 1, lx = by, lw = frame.inside_w - by; - - if (decorations & Decor_Iconify) { - if (frame.iconify_button == None) createIconifyButton(); - - XMoveResizeWindow(blackbox->getXDisplay(), frame.iconify_button, by, by, - frame.button_w, frame.button_w); - XMapWindow(blackbox->getXDisplay(), frame.iconify_button); - XClearWindow(blackbox->getXDisplay(), frame.iconify_button); - - lx += bw; - lw -= bw; - } else if (frame.iconify_button) { - destroyIconifyButton(); + string layout = blackbox->getTitlebarLayout(); + string parsed; + + bool hasclose, hasiconify, hasmaximize, haslabel; + hasclose = hasiconify = hasmaximize = haslabel = false; + + string::const_iterator it, end; + for (it = layout.begin(), end = layout.end(); it != end; ++it) { + switch(*it) { + case 'C': + if (! hasclose && (decorations & Decor_Close)) { + hasclose = true; + parsed += *it; + } + break; + case 'I': + if (! hasiconify && (decorations & Decor_Iconify)) { + hasiconify = true; + parsed += *it; + } + break; + case 'M': + if (! hasmaximize && (decorations & Decor_Maximize)) { + hasmaximize = true; + parsed += *it; + } + break; + case 'L': + if (! haslabel) { + haslabel = true; + parsed += *it; + } + } } - int bx = frame.inside_w - bw; - - if (decorations & Decor_Close) { - if (frame.close_button == None) createCloseButton(); - - XMoveResizeWindow(blackbox->getXDisplay(), frame.close_button, bx, by, - frame.button_w, frame.button_w); - XMapWindow(blackbox->getXDisplay(), frame.close_button); - XClearWindow(blackbox->getXDisplay(), frame.close_button); - - bx -= bw; - lw -= bw; - } else if (frame.close_button) { + if (! hasclose) + destroyCloseButton(); + if (! hasiconify) destroyCloseButton(); + if (! hasmaximize) + destroyCloseButton(); + if (! haslabel) + parsed += 'L'; // require that the label be in the layout + + const unsigned int bsep = frame.bevel_w + 1; // separation between elements + const unsigned int by = frame.bevel_w + 1; + const unsigned int ty = frame.bevel_w; + + frame.label_w = frame.inside_w - bsep * 2 - + (frame.button_w + bsep) * (parsed.size() - 1); + + unsigned int x = bsep; + for (it = parsed.begin(), end = parsed.end(); it != end; ++it) { + switch(*it) { + case 'C': + if (!frame.close_button) createCloseButton(); + XMoveResizeWindow(blackbox->getXDisplay(), frame.close_button, x, by, + frame.button_w, frame.button_w); + x += frame.button_w + bsep; + break; + case 'I': + if (!frame.iconify_button) createIconifyButton(); + XMoveResizeWindow(blackbox->getXDisplay(), frame.iconify_button, x, by, + frame.button_w, frame.button_w); + x += frame.button_w + bsep; + break; + case 'M': + if (!frame.maximize_button) createMaximizeButton(); + XMoveResizeWindow(blackbox->getXDisplay(), frame.maximize_button, x, by, + frame.button_w, frame.button_w); + x += frame.button_w + bsep; + break; + case 'L': + XMoveResizeWindow(blackbox->getXDisplay(), frame.label, x, ty, + frame.label_w, frame.label_h); + x += frame.label_w + bsep; + break; + } } - if (decorations & Decor_Maximize) { - if (frame.maximize_button == None) createMaximizeButton(); - - XMoveResizeWindow(blackbox->getXDisplay(), frame.maximize_button, bx, by, - frame.button_w, frame.button_w); - XMapWindow(blackbox->getXDisplay(), frame.maximize_button); - XClearWindow(blackbox->getXDisplay(), frame.maximize_button); - lw -= bw; - } else if (frame.maximize_button) { - destroyMaximizeButton(); - } - frame.label_w = lw - by; - XMoveResizeWindow(blackbox->getXDisplay(), frame.label, lx, frame.bevel_w, - frame.label_w, frame.label_h); if (redecorate_label) decorateLabel(); - redrawLabel(); redrawAllButtons(); } @@ -2369,6 +2402,18 @@ void BlackboxWindow::buttonPressEvent(XButtonEvent *be) { windowmenu->hide(); } } + // mouse wheel up + } else if (be->button == 4) { + if ((be->window == frame.label || + be->window == frame.title) && + ! flags.shaded) + shade(); + // mouse wheel down + } else if (be->button == 5) { + if ((be->window == frame.label || + be->window == frame.title) && + flags.shaded) + shade(); } } diff --git a/src/blackbox.cc b/src/blackbox.cc index 63a5055b..dd4c278e 100644 --- a/src/blackbox.cc +++ b/src/blackbox.cc @@ -988,6 +988,7 @@ void Blackbox::save_rc(void) { config.setValue("session.cacheLife", resource.cache_life / 60000); config.setValue("session.cacheMax", resource.cache_max); config.setValue("session.styleFile", resource.style_file); + config.setValue("session.titlebarLayout", resource.titlebar_layout); std::for_each(screenList.begin(), screenList.end(), std::mem_fun(&BScreen::save_rc)); @@ -1032,6 +1033,9 @@ void Blackbox::load_rc(void) { if (! config.getValue("session.cacheMax", resource.cache_max)) resource.cache_max = 200; + + if (! config.getValue("session.titlebarLayout", resource.titlebar_layout)) + resource.titlebar_layout = "ILMC"; } diff --git a/src/blackbox.hh b/src/blackbox.hh index e6193ae0..a5434624 100644 --- a/src/blackbox.hh +++ b/src/blackbox.hh @@ -113,6 +113,7 @@ private: int colors_per_channel; timeval auto_raise_delay; unsigned long cache_life, cache_max; + std::string titlebar_layout; } resource; typedef std::map WindowLookup; @@ -241,6 +242,9 @@ public: inline int getColorsPerChannel(void) const { return resource.colors_per_channel; } + inline std::string getTitlebarLayout(void) const + { return resource.titlebar_layout; } + inline const timeval &getAutoRaiseDelay(void) const { return resource.auto_raise_delay; } -- 2.45.2