From e13cb99bd05db49f116b8f1a4925c034dfae60a2 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Thu, 14 Nov 2002 00:23:19 +0000 Subject: cleaning --- src/Slit.cc | 711 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 359 insertions(+), 352 deletions(-) diff --git a/src/Slit.cc b/src/Slit.cc index fe6711b..6aaea47 100644 --- a/src/Slit.cc +++ b/src/Slit.cc @@ -1,3 +1,6 @@ +// Slit.cc for fluxbox +// Copyright (c) 2002 Henrik Kinnunen (fluxgen at linuxmail.org) +// // Slit.cc for Blackbox - an X11 Window manager // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) // @@ -19,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Slit.cc,v 1.23 2002/10/29 15:59:35 fluxgen Exp $ +// $Id: Slit.cc,v 1.24 2002/11/14 00:23:19 fluxgen Exp $ //use GNU extensions #ifndef _GNU_SOURCE @@ -32,8 +35,6 @@ #ifdef SLIT -#include - #include "i18n.hh" #include "fluxbox.hh" #include "Image.hh" @@ -50,57 +51,64 @@ # include #endif // HAVE_SYS_STAT_H +#include // Utility method for extracting name from window namespace { - void getWMName(BScreen *screen, Window window, std::string& name) { - name = ""; - - if (screen != 0 && window != None) { - Display *display = screen->getBaseDisplay()->getXDisplay(); - - XTextProperty text_prop; - char **list; - int num; - I18n *i18n = I18n::instance(); - - if (XGetWMName(display, window, &text_prop)) { - if (text_prop.value && text_prop.nitems > 0) { - if (text_prop.encoding != XA_STRING) { - - text_prop.nitems = strlen((char *) text_prop.value); - - if ((XmbTextPropertyToTextList(display, &text_prop, - &list, &num) == Success) && - (num > 0) && *list) { - name = static_cast(*list); - XFreeStringList(list); - } else - name = (char *)text_prop.value; - - } else - name = (char *)text_prop.value; + +void getWMName(BScreen *screen, Window window, std::string& name) { + name = ""; + + if (screen == 0 || window == None) + return; + + Display *display = BaseDisplay::getXDisplay(); + + XTextProperty text_prop; + char **list; + int num; + I18n *i18n = I18n::instance(); + + if (XGetWMName(display, window, &text_prop)) { + if (text_prop.value && text_prop.nitems > 0) { + if (text_prop.encoding != XA_STRING) { + + text_prop.nitems = strlen((char *) text_prop.value); + + if ((XmbTextPropertyToTextList(display, &text_prop, + &list, &num) == Success) && + (num > 0) && *list) { + name = static_cast(*list); + XFreeStringList(list); } else - name = i18n->getMessage( - FBNLS::WindowSet, FBNLS::WindowUnnamed, - "Unnamed"); - } else { - name = i18n->getMessage( - FBNLS::WindowSet, FBNLS::WindowUnnamed, - "Unnamed"); - } + name = (char *)text_prop.value; + + } else + name = (char *)text_prop.value; + } else { // default name + name = i18n->getMessage( + FBNLS::WindowSet, FBNLS::WindowUnnamed, + "Unnamed"); } + } else { + // default name + name = i18n->getMessage( + FBNLS::WindowSet, FBNLS::WindowUnnamed, + "Unnamed"); } + +} + }; // End anonymous namespace -Slit::Slit(BScreen *scr):screen(scr), timer(this), slitmenu(*this) { +Slit::Slit(BScreen *scr):m_screen(scr), timer(this), slitmenu(*this) { assert(scr); - fluxbox = Fluxbox::instance(); + Fluxbox * const fluxbox = Fluxbox::instance(); - on_top = screen->isSlitOnTop(); - hidden = do_auto_hide = screen->doSlitAutoHide(); + on_top = screen()->isSlitOnTop(); + hidden = do_auto_hide = screen()->doSlitAutoHide(); - display = screen->getBaseDisplay()->getXDisplay(); + frame.window = frame.pixmap = None; @@ -112,8 +120,8 @@ Slit::Slit(BScreen *scr):screen(scr), timer(this), slitmenu(*this) { CWColormap | CWOverrideRedirect | CWEventMask; attrib.background_pixmap = None; attrib.background_pixel = attrib.border_pixel = - screen->getBorderColor()->pixel(); - attrib.colormap = screen->colormap(); + screen()->getBorderColor()->pixel(); + attrib.colormap = screen()->colormap(); attrib.override_redirect = True; attrib.event_mask = SubstructureRedirectMask | ButtonPressMask | EnterWindowMask | LeaveWindowMask; @@ -122,9 +130,9 @@ Slit::Slit(BScreen *scr):screen(scr), timer(this), slitmenu(*this) { frame.width = frame.height = 1; frame.window = - XCreateWindow(display, screen->getRootWindow(), frame.x, frame.y, - frame.width, frame.height, screen->getBorderWidth(), - screen->getDepth(), InputOutput, screen->getVisual(), + XCreateWindow(BaseDisplay::getXDisplay(), screen()->getRootWindow(), frame.x, frame.y, + frame.width, frame.height, screen()->getBorderWidth(), + screen()->getDepth(), InputOutput, screen()->getVisual(), create_mask, &attrib); fluxbox->saveSlitSearch(frame.window, this); @@ -136,15 +144,11 @@ Slit::Slit(BScreen *scr):screen(scr), timer(this), slitmenu(*this) { Slit::~Slit() { - fluxbox->grab(); - - screen->getImageControl()->removeImage(frame.pixmap); + screen()->getImageControl()->removeImage(frame.pixmap); - fluxbox->removeSlitSearch(frame.window); + Fluxbox::instance()->removeSlitSearch(frame.window); - XDestroyWindow(display, frame.window); - - fluxbox->ungrab(); + XDestroyWindow(BaseDisplay::getXDisplay(), frame.window); } @@ -153,133 +157,132 @@ void Slit::addClient(Window w) { if (w == None) return; - fluxbox->grab(); - if (fluxbox->validateWindow(w)) { - // Look for slot in client list by name - SlitClient *client = 0; - std::string match_name; - ::getWMName(screen, w, match_name); - SlitClients::iterator it = clientList.begin(); - SlitClients::iterator it_end = clientList.end(); - bool found_match = false; - for (; it != it_end; ++it) { - // If the name matches... - if ((*it)->match_name == match_name) { - // Use the slot if no window is assigned - if ((*it)->window == None) { - client = (*it); - client->initialize(screen, w); - break; - } - // Otherwise keep looking for an unused match or a non-match - found_match = true; // Possibly redundant - - } else if (found_match) { - // Insert before first non-match after a previously found match? - client = new SlitClient(screen, w); - clientList.insert(it, client); + if (!Fluxbox::instance()->validateWindow(w)) + return; + + // Look for slot in client list by name + SlitClient *client = 0; + std::string match_name; + ::getWMName(screen(), w, match_name); + SlitClients::iterator it = clientList.begin(); + SlitClients::iterator it_end = clientList.end(); + bool found_match = false; + for (; it != it_end; ++it) { + // If the name matches... + if ((*it)->match_name == match_name) { + // Use the slot if no window is assigned + if ((*it)->window == None) { + client = (*it); + client->initialize(screen(), w); break; } + // Otherwise keep looking for an unused match or a non-match + found_match = true; // Possibly redundant + + } else if (found_match) { + // Insert before first non-match after a previously found match? + client = new SlitClient(screen(), w); + clientList.insert(it, client); + break; } - // Append to client list? - if (client == 0) { - client = new SlitClient(screen, w); - clientList.push_back(client); - } - - XWMHints *wmhints = XGetWMHints(display, w); - - if (wmhints) { - if ((wmhints->flags & IconWindowHint) && - (wmhints->icon_window != None)) { - XMoveWindow(display, client->client_window, screen->getWidth() + 10, - screen->getHeight() + 10); - XMapWindow(display, client->client_window); - client->icon_window = wmhints->icon_window; - client->window = client->icon_window; - } else { - client->icon_window = None; - client->window = client->client_window; - } - - XFree(wmhints); + } + // Append to client list? + if (client == 0) { + client = new SlitClient(screen(), w); + clientList.push_back(client); + } + Display *disp = BaseDisplay::getXDisplay(); + XWMHints *wmhints = XGetWMHints(disp, w); + + if (wmhints) { + if ((wmhints->flags & IconWindowHint) && + (wmhints->icon_window != None)) { + XMoveWindow(disp, client->client_window, screen()->getWidth() + 10, + screen()->getHeight() + 10); + XMapWindow(disp, client->client_window); + client->icon_window = wmhints->icon_window; + client->window = client->icon_window; } else { client->icon_window = None; client->window = client->client_window; } - XWindowAttributes attrib; - #ifdef KDE - //Check and see if new client is a KDE dock applet - //If so force reasonable size - bool iskdedockapp=false; - Atom ajunk; - int ijunk; - unsigned long *data = (unsigned long *) 0, uljunk; - - // Check if KDE v2.x dock applet - if (XGetWindowProperty(fluxbox->getXDisplay(), w, - fluxbox->getKWM2DockwindowAtom(), 0l, 1l, False, - fluxbox->getKWM2DockwindowAtom(), + + XFree(wmhints); + } else { + client->icon_window = None; + client->window = client->client_window; + } + XWindowAttributes attrib; +#ifdef KDE + //Check and see if new client is a KDE dock applet + //If so force reasonable size + bool iskdedockapp=false; + Atom ajunk; + int ijunk; + unsigned long *data = (unsigned long *) 0, uljunk; + + // Check if KDE v2.x dock applet + if (XGetWindowProperty(disp, w, + fluxbox->getKWM2DockwindowAtom(), 0l, 1l, False, + fluxbox->getKWM2DockwindowAtom(), + &ajunk, &ijunk, &uljunk, &uljunk, + (unsigned char **) &data) == Success) { + iskdedockapp = (data && data[0] != 0); + XFree((char *) data); + } + + // Check if KDE v1.x dock applet + if (!iskdedockapp) { + if (XGetWindowProperty(disp, w, + fluxbox->getKWM1DockwindowAtom(), 0l, 1l, False, + fluxbox->getKWM1DockwindowAtom(), &ajunk, &ijunk, &uljunk, &uljunk, (unsigned char **) &data) == Success) { iskdedockapp = (data && data[0] != 0); - XFree((char *) data); - } - - // Check if KDE v1.x dock applet - if (!iskdedockapp) { - if (XGetWindowProperty(fluxbox->getXDisplay(), w, - fluxbox->getKWM1DockwindowAtom(), 0l, 1l, False, - fluxbox->getKWM1DockwindowAtom(), - &ajunk, &ijunk, &uljunk, &uljunk, - (unsigned char **) &data) == Success) { - iskdedockapp = (data && data[0] != 0); - XFree((char *) data); - } - } + XFree((char *) data); + } + } - if (iskdedockapp) - client->width = client->height = 24; - else - #endif // KDE - { - if (XGetWindowAttributes(display, client->window, &attrib)) { - client->width = attrib.width; - client->height = attrib.height; - } else { - client->width = client->height = 64; - } + if (iskdedockapp) + client->width = client->height = 24; + else +#endif // KDE + { + if (XGetWindowAttributes(disp, client->window, &attrib)) { + client->width = attrib.width; + client->height = attrib.height; + } else { + client->width = client->height = 64; } + } - XSetWindowBorderWidth(display, client->window, 0); + XSetWindowBorderWidth(disp, client->window, 0); - XSelectInput(display, frame.window, NoEventMask); - XSelectInput(display, client->window, NoEventMask); + XSelectInput(disp, frame.window, NoEventMask); + XSelectInput(disp, client->window, NoEventMask); - XReparentWindow(display, client->window, frame.window, 0, 0); - XMapRaised(display, client->window); - XChangeSaveSet(display, client->window, SetModeInsert); + XReparentWindow(disp, client->window, frame.window, 0, 0); + XMapRaised(disp, client->window); + XChangeSaveSet(disp, client->window, SetModeInsert); - XSelectInput(display, frame.window, SubstructureRedirectMask | - ButtonPressMask | EnterWindowMask | LeaveWindowMask); - XSelectInput(display, client->window, StructureNotifyMask | - SubstructureNotifyMask | EnterWindowMask); - XFlush(display); + XSelectInput(disp, frame.window, SubstructureRedirectMask | + ButtonPressMask | EnterWindowMask | LeaveWindowMask); + XSelectInput(disp, client->window, StructureNotifyMask | + SubstructureNotifyMask | EnterWindowMask); + XFlush(disp); - fluxbox->saveSlitSearch(client->client_window, this); - fluxbox->saveSlitSearch(client->icon_window, this); - reconfigure(); + Fluxbox::instance()->saveSlitSearch(client->client_window, this); + Fluxbox::instance()->saveSlitSearch(client->icon_window, this); + reconfigure(); - saveClientList(); - } + saveClientList(); - fluxbox->ungrab(); } void Slit::removeClient(SlitClient *client, bool remap, bool destroy) { - fluxbox->removeSlitSearch(client->client_window); - fluxbox->removeSlitSearch(client->icon_window); + Fluxbox::instance()->removeSlitSearch(client->client_window); + Fluxbox::instance()->removeSlitSearch(client->icon_window); // Destructive removal? if (destroy) @@ -287,17 +290,18 @@ void Slit::removeClient(SlitClient *client, bool remap, bool destroy) { else // Clear the window info, but keep around to help future sorting? client->initialize(); - screen->removeNetizen(client->window); + screen()->removeNetizen(client->window); - if (remap && fluxbox->validateWindow(client->window)) { - XSelectInput(display, frame.window, NoEventMask); - XSelectInput(display, client->window, NoEventMask); - XReparentWindow(display, client->window, screen->getRootWindow(), + if (remap && Fluxbox::instance()->validateWindow(client->window)) { + Display *disp = BaseDisplay::getXDisplay(); + XSelectInput(disp, frame.window, NoEventMask); + XSelectInput(disp, client->window, NoEventMask); + XReparentWindow(disp, client->window, screen()->getRootWindow(), client->x, client->y); - XChangeSaveSet(display, client->window, SetModeDelete); - XSelectInput(display, frame.window, SubstructureRedirectMask | + XChangeSaveSet(disp, client->window, SetModeDelete); + XSelectInput(disp, frame.window, SubstructureRedirectMask | ButtonPressMask | EnterWindowMask | LeaveWindowMask); - XFlush(display); + XFlush(disp); } // Destructive removal? @@ -307,7 +311,6 @@ void Slit::removeClient(SlitClient *client, bool remap, bool destroy) { void Slit::removeClient(Window w, bool remap) { - fluxbox->grab(); bool reconf = false; @@ -321,13 +324,13 @@ void Slit::removeClient(Window w, bool remap) { break; } } - if (reconf) reconfigure(); + if (reconf) + reconfigure(); - fluxbox->ungrab(); } -void Slit::reconfigure(void) { +void Slit::reconfigure() { frame.width = 0; frame.height = 0; @@ -335,8 +338,8 @@ void Slit::reconfigure(void) { // actually correspond to mapped windows. int num_windows = 0; - switch (screen->getSlitDirection()) { - case VERTICAL: + switch (screen()->getSlitDirection()) { + case VERTICAL: { SlitClients::iterator it = clientList.begin(); SlitClients::iterator it_end = clientList.end(); @@ -344,7 +347,7 @@ void Slit::reconfigure(void) { //client created window? if ((*it)->window != None) { num_windows++; - frame.height += (*it)->height + screen->getBevelWidth(); + frame.height += (*it)->height + screen()->getBevelWidth(); //frame width < client window? if (frame.width < (*it)->width) @@ -356,16 +359,16 @@ void Slit::reconfigure(void) { if (frame.width < 1) frame.width = 1; else - frame.width += (screen->getBevelWidth() * 2); + frame.width += (screen()->getBevelWidth() * 2); if (frame.height < 1) frame.height = 1; else - frame.height += screen->getBevelWidth(); + frame.height += screen()->getBevelWidth(); - break; + break; - case HORIZONTAL: + case HORIZONTAL: { SlitClients::iterator it = clientList.begin(); SlitClients::iterator it_end = clientList.end(); @@ -373,7 +376,7 @@ void Slit::reconfigure(void) { //client created window? if ((*it)->window != None) { num_windows++; - frame.width += (*it)->width + screen->getBevelWidth(); + frame.width += (*it)->width + screen()->getBevelWidth(); //frame height < client height? if (frame.height < (*it)->height) frame.height = (*it)->height; @@ -384,51 +387,52 @@ void Slit::reconfigure(void) { if (frame.width < 1) frame.width = 1; else - frame.width += screen->getBevelWidth(); + frame.width += screen()->getBevelWidth(); if (frame.height < 1) frame.height = 1; else - frame.height += (screen->getBevelWidth() * 2); + frame.height += (screen()->getBevelWidth() * 2); - break; + break; } reposition(); + Display *disp = BaseDisplay::getXDisplay(); - XSetWindowBorderWidth(display ,frame.window, screen->getBorderWidth()); - XSetWindowBorder(display, frame.window, - screen->getBorderColor()->pixel()); + XSetWindowBorderWidth(disp, frame.window, screen()->getBorderWidth()); + XSetWindowBorder(disp, frame.window, + screen()->getBorderColor()->pixel()); //did we actually use slit slots if (num_windows == 0) - XUnmapWindow(display, frame.window); + XUnmapWindow(disp, frame.window); else - XMapWindow(display, frame.window); + XMapWindow(disp, frame.window); Pixmap tmp = frame.pixmap; - BImageControl *image_ctrl = screen->getImageControl(); - const FbTk::Texture *texture = &(screen->getTheme()->getSlitTexture()); + BImageControl *image_ctrl = screen()->getImageControl(); + const FbTk::Texture *texture = &(screen()->getTheme()->getSlitTexture()); if (texture->type() == (FbTk::Texture::FLAT | FbTk::Texture::SOLID)) { frame.pixmap = None; - XSetWindowBackground(display, frame.window, + XSetWindowBackground(disp, frame.window, texture->color().pixel()); } else { frame.pixmap = image_ctrl->renderImage(frame.width, frame.height, texture); - XSetWindowBackgroundPixmap(display, frame.window, frame.pixmap); + XSetWindowBackgroundPixmap(disp, frame.window, frame.pixmap); } if (tmp) image_ctrl->removeImage(tmp); - XClearWindow(display, frame.window); + XClearWindow(disp, frame.window); int x, y; - switch (screen->getSlitDirection()) { + switch (screen()->getSlitDirection()) { case VERTICAL: x = 0; - y = screen->getBevelWidth(); + y = screen()->getBevelWidth(); { SlitClients::iterator it = clientList.begin(); @@ -439,10 +443,10 @@ void Slit::reconfigure(void) { continue; x = (frame.width - (*it)->width) / 2; - - XMoveResizeWindow(display, (*it)->window, x, y, + Display *disp = BaseDisplay::getXDisplay(); + XMoveResizeWindow(disp, (*it)->window, x, y, (*it)->width, (*it)->height); - XMapWindow(display, (*it)->window); + XMapWindow(disp, (*it)->window); // for ICCCM compliance (*it)->x = x; @@ -451,7 +455,7 @@ void Slit::reconfigure(void) { XEvent event; event.type = ConfigureNotify; - event.xconfigure.display = display; + event.xconfigure.display = disp; event.xconfigure.event = (*it)->window; event.xconfigure.window = (*it)->window; event.xconfigure.x = x; @@ -462,17 +466,17 @@ void Slit::reconfigure(void) { event.xconfigure.above = frame.window; event.xconfigure.override_redirect = False; - XSendEvent(display, (*it)->window, False, StructureNotifyMask, + XSendEvent(disp, (*it)->window, False, StructureNotifyMask, &event); - y += (*it)->height + screen->getBevelWidth(); + y += (*it)->height + screen()->getBevelWidth(); } } break; case HORIZONTAL: - x = screen->getBevelWidth(); + x = screen()->getBevelWidth(); y = 0; { @@ -485,9 +489,9 @@ void Slit::reconfigure(void) { y = (frame.height - (*it)->height) / 2; - XMoveResizeWindow(display, (*it)->window, x, y, + XMoveResizeWindow(disp, (*it)->window, x, y, (*it)->width, (*it)->height); - XMapWindow(display, (*it)->window); + XMapWindow(disp, (*it)->window); // for ICCCM compliance (*it)->x = x; @@ -496,21 +500,21 @@ void Slit::reconfigure(void) { XEvent event; event.type = ConfigureNotify; - event.xconfigure.display = display; + event.xconfigure.display = disp; event.xconfigure.event = (*it)->window; event.xconfigure.window = (*it)->window; - event.xconfigure.x = frame.x + x + screen->getBorderWidth(); - event.xconfigure.y = frame.y + y + screen->getBorderWidth(); + event.xconfigure.x = frame.x + x + screen()->getBorderWidth(); + event.xconfigure.y = frame.y + y + screen()->getBorderWidth(); event.xconfigure.width = (*it)->width; event.xconfigure.height = (*it)->height; event.xconfigure.border_width = 0; event.xconfigure.above = frame.window; event.xconfigure.override_redirect = False; - XSendEvent(display, (*it)->window, False, StructureNotifyMask, + XSendEvent(disp, (*it)->window, False, StructureNotifyMask, &event); - x += (*it)->width + screen->getBevelWidth(); + x += (*it)->width + screen()->getBevelWidth(); } } @@ -527,57 +531,57 @@ void Slit::reposition() { head_w, head_h; #ifdef XINERAMA - if (screen->hasXinerama()) { - unsigned int head = screen->getSlitOnHead(); + if (screen()->hasXinerama()) { + unsigned int head = screen()->getSlitOnHead(); - head_x = screen->getHeadX(head); - head_y = screen->getHeadY(head); - head_w = screen->getHeadWidth(head); - head_h = screen->getHeadHeight(head); + head_x = screen()->getHeadX(head); + head_y = screen()->getHeadY(head); + head_w = screen()->getHeadWidth(head); + head_h = screen()->getHeadHeight(head); } else { - head_w = screen->getWidth(); - head_h = screen->getHeight(); + head_w = screen()->getWidth(); + head_h = screen()->getHeight(); } #else // !XINERAMA - head_w = screen->getWidth(); - head_h = screen->getHeight(); + head_w = screen()->getWidth(); + head_h = screen()->getHeight(); #endif // XINERAMA // place the slit in the appropriate place - switch (screen->getSlitPlacement()) { + switch (screen()->getSlitPlacement()) { case TOPLEFT: frame.x = head_x; frame.y = head_y; - if (screen->getSlitDirection() == VERTICAL) { - frame.x_hidden = screen->getBevelWidth() - - screen->getBorderWidth() - frame.width; + if (screen()->getSlitDirection() == VERTICAL) { + frame.x_hidden = screen()->getBevelWidth() - + screen()->getBorderWidth() - frame.width; frame.y_hidden = head_y; } else { frame.x_hidden = head_x; - frame.y_hidden = screen->getBevelWidth() - - screen->getBorderWidth() - frame.height; + frame.y_hidden = screen()->getBevelWidth() - + screen()->getBorderWidth() - frame.height; } break; case CENTERLEFT: frame.x = head_x; frame.y = head_y + (head_h - frame.height) / 2; - frame.x_hidden = head_x + screen->getBevelWidth() - - screen->getBorderWidth() - frame.width; + frame.x_hidden = head_x + screen()->getBevelWidth() - + screen()->getBorderWidth() - frame.width; frame.y_hidden = frame.y; break; case BOTTOMLEFT: frame.x = head_x; - frame.y = head_h - frame.height - screen->getBorderWidth2x(); - if (screen->getSlitDirection() == VERTICAL) { - frame.x_hidden = head_x + screen->getBevelWidth() - - screen->getBorderWidth() - frame.width; + frame.y = head_h - frame.height - screen()->getBorderWidth2x(); + if (screen()->getSlitDirection() == VERTICAL) { + frame.x_hidden = head_x + screen()->getBevelWidth() - + screen()->getBorderWidth() - frame.width; frame.y_hidden = frame.y; } else { frame.x_hidden = head_x; frame.y_hidden = head_y + head_h - - screen->getBevelWidth() - screen->getBorderWidth(); + screen()->getBevelWidth() - screen()->getBorderWidth(); } break; @@ -585,85 +589,88 @@ void Slit::reposition() { frame.x = head_x + ((head_w - frame.width) / 2); frame.y = head_y; frame.x_hidden = frame.x; - frame.y_hidden = head_y + screen->getBevelWidth() - - screen->getBorderWidth() - frame.height; + frame.y_hidden = head_y + screen()->getBevelWidth() - + screen()->getBorderWidth() - frame.height; break; case BOTTOMCENTER: frame.x = head_x + ((head_w - frame.width) / 2); - frame.y = head_y + head_h - frame.height - screen->getBorderWidth2x(); + frame.y = head_y + head_h - frame.height - screen()->getBorderWidth2x(); frame.x_hidden = frame.x; frame.y_hidden = head_y + head_h - - screen->getBevelWidth() - screen->getBorderWidth(); + screen()->getBevelWidth() - screen()->getBorderWidth(); break; case TOPRIGHT: - frame.x = head_x + head_w - frame.width - screen->getBorderWidth2x(); + frame.x = head_x + head_w - frame.width - screen()->getBorderWidth2x(); frame.y = head_y; - if (screen->getSlitDirection() == VERTICAL) { + if (screen()->getSlitDirection() == VERTICAL) { frame.x_hidden = head_x + head_w - - screen->getBevelWidth() - screen->getBorderWidth(); + screen()->getBevelWidth() - screen()->getBorderWidth(); frame.y_hidden = head_y; } else { frame.x_hidden = frame.x; - frame.y_hidden = head_y + screen->getBevelWidth() - - screen->getBorderWidth() - frame.height; + frame.y_hidden = head_y + screen()->getBevelWidth() - + screen()->getBorderWidth() - frame.height; } break; case CENTERRIGHT: default: - frame.x = head_x + head_w - frame.width - screen->getBorderWidth2x(); + frame.x = head_x + head_w - frame.width - screen()->getBorderWidth2x(); frame.y = head_y + ((head_h - frame.height) / 2); frame.x_hidden = head_x + head_w - - screen->getBevelWidth() - screen->getBorderWidth(); + screen()->getBevelWidth() - screen()->getBorderWidth(); frame.y_hidden = frame.y; break; case BOTTOMRIGHT: - frame.x = head_x + head_w - frame.width - screen->getBorderWidth2x(); - frame.y = head_y + head_h - frame.height - screen->getBorderWidth2x(); - if (screen->getSlitDirection() == VERTICAL) { + frame.x = head_x + head_w - frame.width - screen()->getBorderWidth2x(); + frame.y = head_y + head_h - frame.height - screen()->getBorderWidth2x(); + if (screen()->getSlitDirection() == VERTICAL) { frame.x_hidden = head_x + head_w - - screen->getBevelWidth() - screen->getBorderWidth(); + screen()->getBevelWidth() - screen()->getBorderWidth(); frame.y_hidden = frame.y; } else { frame.x_hidden = frame.x; frame.y_hidden = head_y + head_h - - screen->getBevelWidth() - screen->getBorderWidth(); + screen()->getBevelWidth() - screen()->getBorderWidth(); } break; } - const Toolbar * const tbar = screen->getToolbar(); - int sw = frame.width + screen->getBorderWidth2x(), - sh = frame.height + screen->getBorderWidth2x(), - tw = tbar->width() + screen->getBorderWidth(), - th = tbar->height() + screen->getBorderWidth(); + const Toolbar * const tbar = screen()->getToolbar(); + int sw = frame.width + screen()->getBorderWidth2x(), + sh = frame.height + screen()->getBorderWidth2x(), + tw = tbar->width() + screen()->getBorderWidth(), + th = tbar->height() + screen()->getBorderWidth(); if (tbar->x() < frame.x + sw && tbar->x() + tw > frame.x && tbar->y() < frame.y + sh && tbar->y() + th > frame.y) { if (frame.y < th) { frame.y += tbar->getExposedHeight(); - if (screen->getSlitDirection() == VERTICAL) + if (screen()->getSlitDirection() == VERTICAL) frame.y_hidden += tbar->getExposedHeight(); else frame.y_hidden = frame.y; } else { frame.y -= tbar->getExposedHeight(); - if (screen->getSlitDirection() == VERTICAL) + if (screen()->getSlitDirection() == VERTICAL) frame.y_hidden -= tbar->getExposedHeight(); else frame.y_hidden = frame.y; } } - if (hidden) - XMoveResizeWindow(display, frame.window, frame.x_hidden, + Display *disp = BaseDisplay::getXDisplay(); + + if (hidden) { + XMoveResizeWindow(disp, frame.window, frame.x_hidden, frame.y_hidden, frame.width, frame.height); - else - XMoveResizeWindow(display, frame.window, frame.x, + } else { + XMoveResizeWindow(disp, frame.window, frame.x, frame.y, frame.width, frame.height); + } } @@ -675,14 +682,15 @@ void Slit::shutdown() { void Slit::buttonPressEvent(XButtonEvent *e) { - if (e->window != frame.window) return; + if (e->window != frame.window) + return; if (e->button == Button1 && (! on_top)) { Workspace::Stack st; st.push_back(frame.window); - screen->raiseWindows(st); + screen()->raiseWindows(st); } else if (e->button == Button2 && (! on_top)) { - XLowerWindow(display, frame.window); + XLowerWindow(BaseDisplay::getXDisplay(), frame.window); } else if (e->button == Button3) { if (! slitmenu.isVisible()) { int x = e->x_root - (slitmenu.width() / 2), @@ -690,13 +698,13 @@ void Slit::buttonPressEvent(XButtonEvent *e) { if (x < 0) x = 0; - else if (x + slitmenu.width() > screen->getWidth()) - x = screen->getWidth() - slitmenu.width(); + else if (x + slitmenu.width() > screen()->getWidth()) + x = screen()->getWidth() - slitmenu.width(); if (y < 0) y = 0; - else if (y + slitmenu.height() > screen->getHeight()) - y = screen->getHeight() - slitmenu.height(); + else if (y + slitmenu.height() > screen()->getHeight()) + y = screen()->getHeight() - slitmenu.height(); slitmenu.move(x, y); slitmenu.show(); @@ -735,57 +743,58 @@ void Slit::leaveNotifyEvent(XCrossingEvent *) { void Slit::configureRequestEvent(XConfigureRequestEvent *e) { - fluxbox->grab(); - - if (fluxbox->validateWindow(e->window)) { - bool reconf = false; - XWindowChanges xwc; - - xwc.x = e->x; - xwc.y = e->y; - xwc.width = e->width; - xwc.height = e->height; - xwc.border_width = 0; - xwc.sibling = e->above; - xwc.stack_mode = e->detail; - - XConfigureWindow(display, e->window, e->value_mask, &xwc); - - SlitClients::iterator it = clientList.begin(); - SlitClients::iterator it_end = clientList.end(); - for (; it != it_end; ++it) - if ((*it)->window == e->window) - if ((*it)->width != ((unsigned) e->width) || - (*it)->height != ((unsigned) e->height)) { - (*it)->width = (unsigned) e->width; - (*it)->height = (unsigned) e->height; - - reconf = true; - - break; - } - if (reconf) reconfigure(); + if (!Fluxbox::instance()->validateWindow(e->window)) + return; + + bool reconf = false; + XWindowChanges xwc; + + xwc.x = e->x; + xwc.y = e->y; + xwc.width = e->width; + xwc.height = e->height; + xwc.border_width = 0; + xwc.sibling = e->above; + xwc.stack_mode = e->detail; + + XConfigureWindow(BaseDisplay::getXDisplay(), e->window, e->value_mask, &xwc); + + SlitClients::iterator it = clientList.begin(); + SlitClients::iterator it_end = clientList.end(); + for (; it != it_end; ++it) { + if ((*it)->window == e->window) { + if ((*it)->width != ((unsigned) e->width) || + (*it)->height != ((unsigned) e->height)) { + (*it)->width = (unsigned) e->width; + (*it)->height = (unsigned) e->height; + + reconf = true; //requires reconfiguration + break; + } + } } - fluxbox->ungrab(); + if (reconf) + reconfigure(); } void Slit::timeout() { hidden = ! hidden; + Display *disp = BaseDisplay::getXDisplay(); if (hidden) - XMoveWindow(display, frame.window, frame.x_hidden, frame.y_hidden); + XMoveWindow(disp, frame.window, frame.x_hidden, frame.y_hidden); else - XMoveWindow(display, frame.window, frame.x, frame.y); + XMoveWindow(disp, frame.window, frame.x, frame.y); } void Slit::loadClientList() { - const std::string &filename = fluxbox->getSlitlistFilename(); + const std::string &filename = Fluxbox::instance()->getSlitlistFilename(); struct stat buf; if (!stat(filename.c_str(), &buf)) { - std::ifstream file(fluxbox->getSlitlistFilename().c_str()); + std::ifstream file(Fluxbox::instance()->getSlitlistFilename().c_str()); std::string name; while (! file.eof()) { name = ""; @@ -798,8 +807,8 @@ void Slit::loadClientList() { } } -void Slit::saveClientList(void) { - const std::string &filename = fluxbox->getSlitlistFilename(); +void Slit::saveClientList() { + const std::string &filename = Fluxbox::instance()->getSlitlistFilename(); std::ofstream file(filename.c_str()); SlitClients::iterator it = clientList.begin(); SlitClients::iterator it_end = clientList.end(); @@ -813,10 +822,28 @@ void Slit::saveClientList(void) { prevName = name; } } +void Slit::setOnTop(bool val) { + on_top = val; + screen()->saveSlitOnTop(val); + + if (isOnTop()) + screen()->raiseWindows(Workspace::Stack()); + +} -Slitmenu::Slitmenu(Slit &sl) : Basemenu(sl.screen), -slit(sl) { +void Slit::setAutoHide(bool val) { + do_auto_hide = val; + screen()->saveSlitAutoHide(val); +} + +Slitmenu::Slitmenu(Slit &sl) : Basemenu(sl.screen()), +slit(sl), +#ifdef XINERAMA +m_headmenu(0), +#endif // XINERAMA +m_placementmenu(*this), +m_directionmenu(*this) { I18n *i18n = I18n::instance(); using namespace FBNLS; @@ -825,27 +852,25 @@ slit(sl) { "Slit")); setInternalMenu(); - directionmenu = new Directionmenu(this); - placementmenu = new Placementmenu(this); + #ifdef XINERAMA if (screen()->hasXinerama()) { // only create if we need - headmenu = new Headmenu(this); + m_headmenu.reset(new Headmenu(this)); } #endif // XINERAMA insert(i18n->getMessage( CommonSet, CommonDirectionTitle, "Direction"), - directionmenu); + &m_directionmenu); insert(i18n->getMessage( CommonSet, CommonPlacementTitle, "Placement"), - placementmenu); + &m_placementmenu); #ifdef XINERAMA - //TODO: NLS if (screen()->hasXinerama()) { - insert(i18n->getMessage(0, 0, "Place on Head"), headmenu); + insert(i18n->getMessage(0, 0, "Place on Head"), m_headmenu.get()); } #endif // XINERAMA @@ -865,13 +890,7 @@ slit(sl) { Slitmenu::~Slitmenu() { - delete directionmenu; - delete placementmenu; -#ifdef XINERAMA - if (screen()->hasXinerama()) { - delete headmenu; - } -#endif // XINERAMA + } @@ -881,28 +900,17 @@ void Slitmenu::itemSelected(int button, unsigned int index) { if (! item) return; switch (item->function()) { - case 1: // always on top - { - bool change = ((slit.isOnTop()) ? false : true); - slit.on_top = change; - screen()->saveSlitOnTop(change); - setItemSelected(2, change); - - if (slit.isOnTop()) - screen()->raiseWindows(Workspace::Stack()); - + case 1: + // toggle on top + slit.setOnTop(slit.isOnTop() ? false : true); + setItemSelected(2, slit.isOnTop()); break; - } - case 2: // auto hide - { - bool change = (slit.doAutoHide() ? false : true); - slit.do_auto_hide = change; - screen()->saveSlitAutoHide(change); - setItemSelected(3, change); + slit.setAutoHide(slit.doAutoHide() ? false : true); + setItemSelected(3, slit.doAutoHide()); break; } - } + //save the new configuration Fluxbox::instance()->save_rc(); update(); @@ -910,19 +918,19 @@ void Slitmenu::itemSelected(int button, unsigned int index) { } -void Slitmenu::internal_hide(void) { +void Slitmenu::internal_hide() { Basemenu::internal_hide(); if (slit.doAutoHide()) slit.timeout(); } -void Slitmenu::reconfigure(void) { - directionmenu->reconfigure(); - placementmenu->reconfigure(); +void Slitmenu::reconfigure() { + m_directionmenu.reconfigure(); + m_placementmenu.reconfigure(); #ifdef XINERAMA - if (screen()->hasXinerama()) { - headmenu->reconfigure(); + if (m_headmenu.get() != 0) { + m_headmenu->reconfigure(); } #endif // XINERAMA setItemSelected(2, slit.isOnTop()); @@ -932,7 +940,7 @@ void Slitmenu::reconfigure(void) { } -Slitmenu::Directionmenu::Directionmenu(Slitmenu *sm) : Basemenu(sm->screen()), +Slitmenu::Directionmenu::Directionmenu(Slitmenu &sm) : Basemenu(sm.screen()), slitmenu(sm) { I18n *i18n = I18n::instance(); @@ -963,7 +971,8 @@ slitmenu(sm) { void Slitmenu::Directionmenu::itemSelected(int button, unsigned int index) { if (button == 1) { BasemenuItem *item = find(index); - if (! item) return; + if (item == 0) + return; screen()->saveSlitDirection(item->function()); @@ -976,12 +985,12 @@ void Slitmenu::Directionmenu::itemSelected(int button, unsigned int index) { } Fluxbox::instance()->save_rc(); hide(); - slitmenu->slit.reconfigure(); + slitmenu.slit.reconfigure(); } } -Slitmenu::Placementmenu::Placementmenu(Slitmenu *sm) : Basemenu(sm->screen()), +Slitmenu::Placementmenu::Placementmenu(Slitmenu &sm) : Basemenu(sm.screen()), slitmenu(sm) { I18n *i18n = I18n::instance(); @@ -1038,7 +1047,7 @@ void Slitmenu::Placementmenu::itemSelected(int button, unsigned int index) { if (item->function()) { screen()->saveSlitPlacement(item->function()); hide(); - slitmenu->slit.reconfigure(); + slitmenu.slit.reconfigure(); Fluxbox::instance()->save_rc(); } } @@ -1080,14 +1089,12 @@ void Slitmenu::Headmenu::itemSelected(int button, unsigned int index) { #endif // XINERAMA -Slit::SlitClient::SlitClient(const char *name) -{ +Slit::SlitClient::SlitClient(const char *name) { initialize(); - match_name = name; + match_name = (name == 0 ? "" : name); } -Slit::SlitClient::SlitClient(BScreen *screen, Window w) -{ +Slit::SlitClient::SlitClient(BScreen *screen, Window w) { initialize(screen, w); } -- cgit v0.11.2