X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2FWindow.cc;h=342864c9e11d4cbd48208e6555983e4158d3db11;hb=e7c332a586280ac1ea9d0f993d637802d64c9f87;hp=b81f1b90b55b8d27d0d60d214f526aacf530f723;hpb=8d3c97389f23271c7b44a726111c97d34bc2ced2;p=chaz%2Fopenbox diff --git a/src/Window.cc b/src/Window.cc index b81f1b90..342864c9 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -1,6 +1,7 @@ // Window.cc for Openbox -// Copyright (c) 2001 Sean 'Shaleh' Perry -// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) +// Copyright (c) 2002 - 2002 Ben Jansens (ben at orodu.net) +// Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry (shaleh at debian.org) +// Copyright (c) 1997 - 2000 Brad Hughes (bhughes at tcac.net) // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), @@ -33,9 +34,9 @@ #include #include -#ifdef STDC_HEADERS +#ifdef HAVE_STRING_H # include -#endif // STDC_HEADERS +#endif // HAVE_STRING_H #ifdef DEBUG # ifdef HAVE_STDIO_H @@ -54,22 +55,22 @@ #ifdef SLIT # include "Slit.h" #endif // SLIT +#include "Util.h" /* * Initializes the class with default values/the window's set initial values. */ -OpenboxWindow::OpenboxWindow(Openbox *b, Window w, BScreen *s) { +OpenboxWindow::OpenboxWindow(Openbox &o, Window w, BScreen *s) : openbox(o) { #ifdef DEBUG - fprintf(stderr, i18n->getMessage(WindowSet, WindowCreating, - "OpenboxWindow::OpenboxWindow(): creating 0x%lx\n"), - w); + fprintf(stderr, i18n(WindowSet, WindowCreating, + "OpenboxWindow::OpenboxWindow(): creating 0x%lx\n"), + w); #endif // DEBUG client.window = w; - openbox = b; - display = openbox->getXDisplay(); + display = openbox.getXDisplay(); - openbox->grab(); + openbox.grab(); if (! validateClient()) return; // fetch client size and placement @@ -78,28 +79,28 @@ OpenboxWindow::OpenboxWindow(Openbox *b, Window w, BScreen *s) { (! wattrib.screen) || wattrib.override_redirect) { #ifdef DEBUG fprintf(stderr, - i18n->getMessage(WindowSet, WindowXGetWindowAttributesFail, - "OpenboxWindow::OpenboxWindow(): XGetWindowAttributes " - "failed\n")); + i18n(WindowSet, WindowXGetWindowAttributesFail, + "OpenboxWindow::OpenboxWindow(): XGetWindowAttributes " + "failed\n")); #endif // DEBUG - b->ungrab(); + openbox.ungrab(); return; } if (s) { screen = s; } else { - screen = openbox->searchScreen(RootWindowOfScreen(wattrib.screen)); + screen = openbox.searchScreen(RootWindowOfScreen(wattrib.screen)); if (! screen) { #ifdef DEBUG - fprintf(stderr, i18n->getMessage(WindowSet, WindowCannotFindScreen, - "OpenboxWindow::OpenboxWindow(): can't find screen\n" - "\tfor root window 0x%lx\n"), - RootWindowOfScreen(wattrib.screen)); + fprintf(stderr, i18n(WindowSet, WindowCannotFindScreen, + "OpenboxWindow::OpenboxWindow(): can't find screen\n" + "\tfor root window 0x%lx\n"), + RootWindowOfScreen(wattrib.screen)); #endif // DEBUG - b->ungrab(); + openbox.ungrab(); return; } } @@ -152,8 +153,8 @@ OpenboxWindow::OpenboxWindow(Openbox *b, Window w, BScreen *s) { lastButtonPressTime = 0; image_ctrl = screen->getImageControl(); - timer = new BTimer(openbox, this); - timer->setTimeout(openbox->getAutoRaiseDelay()); + timer = new BTimer(openbox, *this); + timer->setTimeout(openbox.getAutoRaiseDelay()); timer->fireOnce(True); getOpenboxHints(); @@ -169,35 +170,34 @@ OpenboxWindow::OpenboxWindow(Openbox *b, Window w, BScreen *s) { #ifdef SLIT if (client.initial_state == WithdrawnState) { screen->getSlit()->addClient(client.window); + openbox.ungrab(); delete this; - - b->ungrab(); return; } #endif // SLIT flags.managed = True; - openbox->saveWindowSearch(client.window, this); + openbox.saveWindowSearch(client.window, this); // determine if this is a transient window Window win; if (XGetTransientForHint(display, client.window, &win)) { if (win && (win != client.window)) { OpenboxWindow *tr; - if ((tr = openbox->searchWindow(win))) { - while (tr->client.transient) tr = tr->client.transient; - client.transient_for = tr; - tr->client.transient = this; - flags.stuck = client.transient_for->flags.stuck; - flags.transient = True; + if ((tr = openbox.searchWindow(win))) { + while (tr->client.transient) tr = tr->client.transient; + client.transient_for = tr; + tr->client.transient = this; + flags.stuck = client.transient_for->flags.stuck; + flags.transient = True; } else if (win == client.window_group) { - if ((tr = openbox->searchGroup(win, this))) { - while (tr->client.transient) tr = tr->client.transient; - client.transient_for = tr; - tr->client.transient = this; - flags.stuck = client.transient_for->flags.stuck; - flags.transient = True; - } + if ((tr = openbox.searchGroup(win, this))) { + while (tr->client.transient) tr = tr->client.transient; + client.transient_for = tr; + tr->client.transient = this; + flags.stuck = client.transient_for->flags.stuck; + flags.transient = True; + } } } @@ -210,68 +210,68 @@ OpenboxWindow::OpenboxWindow(Openbox *b, Window w, BScreen *s) { if ((client.normal_hint_flags & PMinSize) && (client.normal_hint_flags & PMaxSize) && - client.max_width <= client.min_width && + client.max_width <= client.min_width && client.max_height <= client.min_height) { decorations.maximize = decorations.handle = functions.resize = functions.maximize = False; } upsize(); - Bool place_window = True; - if (openbox->isStartup() || flags.transient || + place_window = true; + if (openbox.isStartup() || flags.transient || client.normal_hint_flags & (PPosition|USPosition)) { setGravityOffsets(); - if ((openbox->isStartup()) || - (frame.x >= 0 && - (signed) (frame.y + frame.y_border) >= 0 && - frame.x <= (signed) screen->getWidth() && - frame.y <= (signed) screen->getHeight())) - place_window = False; + if ((openbox.isStartup()) || + (frame.x >= 0 && + (signed) (frame.y + frame.y_border) >= 0 && + frame.x <= (signed) screen->size().w() && + frame.y <= (signed) screen->size().h())) + place_window = false; } frame.window = createToplevelWindow(frame.x, frame.y, frame.width, - frame.height, - frame.border_w); - openbox->saveWindowSearch(frame.window, this); + frame.height, + frame.border_w); + openbox.saveWindowSearch(frame.window, this); frame.plate = createChildWindow(frame.window); - openbox->saveWindowSearch(frame.plate, this); + openbox.saveWindowSearch(frame.plate, this); if (decorations.titlebar) { frame.title = createChildWindow(frame.window); frame.label = createChildWindow(frame.title); - openbox->saveWindowSearch(frame.title, this); - openbox->saveWindowSearch(frame.label, this); + openbox.saveWindowSearch(frame.title, this); + openbox.saveWindowSearch(frame.label, this); } if (decorations.handle) { frame.handle = createChildWindow(frame.window); - openbox->saveWindowSearch(frame.handle, this); + openbox.saveWindowSearch(frame.handle, this); frame.left_grip = - createChildWindow(frame.handle, openbox->getLowerLeftAngleCursor()); - openbox->saveWindowSearch(frame.left_grip, this); + createChildWindow(frame.handle, openbox.getLowerLeftAngleCursor()); + openbox.saveWindowSearch(frame.left_grip, this); frame.right_grip = - createChildWindow(frame.handle, openbox->getLowerRightAngleCursor()); - openbox->saveWindowSearch(frame.right_grip, this); + createChildWindow(frame.handle, openbox.getLowerRightAngleCursor()); + openbox.saveWindowSearch(frame.right_grip, this); } associateClientWindow(); - if (! screen->isSloppyFocus()) - openbox->grabButton(Button1, 0, frame.plate, True, ButtonPressMask, - GrabModeSync, GrabModeSync, None, None); + if (! screen->sloppyFocus()) + openbox.grabButton(Button1, 0, frame.plate, True, ButtonPressMask, + GrabModeSync, GrabModeSync, frame.plate, None); - openbox->grabButton(Button1, Mod1Mask, frame.window, True, - ButtonReleaseMask | ButtonMotionMask, GrabModeAsync, - GrabModeAsync, None, openbox->getMoveCursor()); - openbox->grabButton(Button2, Mod1Mask, frame.window, True, - ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None); - openbox->grabButton(Button3, Mod1Mask, frame.window, True, - ButtonReleaseMask | ButtonMotionMask, GrabModeAsync, - GrabModeAsync, None, None); + openbox.grabButton(Button1, Mod1Mask, frame.window, True, + ButtonReleaseMask | ButtonMotionMask, GrabModeAsync, + GrabModeAsync, frame.window, openbox.getMoveCursor()); + openbox.grabButton(Button2, Mod1Mask, frame.window, True, + ButtonReleaseMask, GrabModeAsync, GrabModeAsync, frame.window, None); + openbox.grabButton(Button3, Mod1Mask, frame.window, True, + ButtonReleaseMask | ButtonMotionMask, GrabModeAsync, + GrabModeAsync, frame.window, None); positionWindows(); XRaiseWindow(display, frame.plate); @@ -280,7 +280,7 @@ OpenboxWindow::OpenboxWindow(Openbox *b, Window w, BScreen *s) { XMapSubwindows(display, frame.window); if (decorations.menu) - windowmenu = new Windowmenu(this); + windowmenu = new Windowmenu(*this); decorate(); @@ -304,7 +304,7 @@ OpenboxWindow::OpenboxWindow(Openbox *b, Window w, BScreen *s) { setFocusFlag(False); - openbox->ungrab(); + openbox.ungrab(); } @@ -314,9 +314,14 @@ OpenboxWindow::~OpenboxWindow(void) { XUngrabPointer(display, CurrentTime); } - if (workspace_number != -1 && window_number != -1) - screen->getWorkspace(workspace_number)->removeWindow(this); - else if (flags.iconic) + if (workspace_number != -1 && window_number != -1) { + if (flags.stuck) { + // make sure no other workspaces think that we're focused + for (int i=0; i < screen->getWorkspaceCount(); i++) + screen->getWorkspace(i)->removeWindow(this); + } else + screen->getWorkspace(workspace_number)->removeWindow(this); + } else if (flags.iconic) screen->removeIcon(this); if (timer) { @@ -339,7 +344,7 @@ OpenboxWindow::~OpenboxWindow(void) { XFree(client.openbox_hint); if (client.window_group) - openbox->removeGroupSearch(client.window_group); + openbox.removeGroupSearch(client.window_group); if (flags.transient && client.transient_for) client.transient_for->client.transient = client.transient; @@ -347,17 +352,17 @@ OpenboxWindow::~OpenboxWindow(void) { client.transient->client.transient_for = client.transient_for; if (frame.close_button) { - openbox->removeWindowSearch(frame.close_button); + openbox.removeWindowSearch(frame.close_button); XDestroyWindow(display, frame.close_button); } if (frame.iconify_button) { - openbox->removeWindowSearch(frame.iconify_button); + openbox.removeWindowSearch(frame.iconify_button); XDestroyWindow(display, frame.iconify_button); } if (frame.maximize_button) { - openbox->removeWindowSearch(frame.maximize_button); + openbox.removeWindowSearch(frame.maximize_button); XDestroyWindow(display, frame.maximize_button); } @@ -374,8 +379,8 @@ OpenboxWindow::~OpenboxWindow(void) { if( frame.ulabel) image_ctrl->removeImage(frame.ulabel); - openbox->removeWindowSearch(frame.label); - openbox->removeWindowSearch(frame.title); + openbox.removeWindowSearch(frame.label); + openbox.removeWindowSearch(frame.title); XDestroyWindow(display, frame.label); XDestroyWindow(display, frame.title); } @@ -393,9 +398,9 @@ OpenboxWindow::~OpenboxWindow(void) { if (frame.ugrip) image_ctrl->removeImage(frame.ugrip); - openbox->removeWindowSearch(frame.handle); - openbox->removeWindowSearch(frame.right_grip); - openbox->removeWindowSearch(frame.left_grip); + openbox.removeWindowSearch(frame.handle); + openbox.removeWindowSearch(frame.right_grip); + openbox.removeWindowSearch(frame.left_grip); XDestroyWindow(display, frame.right_grip); XDestroyWindow(display, frame.left_grip); XDestroyWindow(display, frame.handle); @@ -411,17 +416,17 @@ OpenboxWindow::~OpenboxWindow(void) { image_ctrl->removeImage(frame.pbutton); if (frame.plate) { - openbox->removeWindowSearch(frame.plate); + openbox.removeWindowSearch(frame.plate); XDestroyWindow(display, frame.plate); } if (frame.window) { - openbox->removeWindowSearch(frame.window); + openbox.removeWindowSearch(frame.window); XDestroyWindow(display, frame.window); } if (flags.managed) { - openbox->removeWindowSearch(client.window); + openbox.removeWindowSearch(client.window); screen->removeNetizen(client.window); } } @@ -433,23 +438,23 @@ OpenboxWindow::~OpenboxWindow(void) { * Returns: the newly created window */ Window OpenboxWindow::createToplevelWindow(int x, int y, unsigned int width, - unsigned int height, - unsigned int borderwidth) + unsigned int height, + unsigned int borderwidth) { XSetWindowAttributes attrib_create; unsigned long create_mask = CWBackPixmap | CWBorderPixel | CWColormap | - CWOverrideRedirect | CWEventMask; + CWOverrideRedirect | CWEventMask; attrib_create.background_pixmap = None; attrib_create.colormap = screen->getColormap(); attrib_create.override_redirect = True; attrib_create.event_mask = ButtonPressMask | ButtonReleaseMask | - ButtonMotionMask | EnterWindowMask; + ButtonMotionMask | EnterWindowMask; return XCreateWindow(display, screen->getRootWindow(), x, y, width, height, - borderwidth, screen->getDepth(), InputOutput, - screen->getVisual(), create_mask, - &attrib_create); + borderwidth, screen->getDepth(), InputOutput, + screen->getVisual(), create_mask, + &attrib_create); } @@ -460,12 +465,12 @@ Window OpenboxWindow::createToplevelWindow(int x, int y, unsigned int width, Window OpenboxWindow::createChildWindow(Window parent, Cursor cursor) { XSetWindowAttributes attrib_create; unsigned long create_mask = CWBackPixmap | CWBorderPixel | - CWEventMask; + CWEventMask; attrib_create.background_pixmap = None; attrib_create.event_mask = ButtonPressMask | ButtonReleaseMask | - ButtonMotionMask | ExposureMask | - EnterWindowMask | LeaveWindowMask; + ButtonMotionMask | ExposureMask | + EnterWindowMask | LeaveWindowMask; if (cursor) { create_mask |= CWCursor; @@ -473,8 +478,8 @@ Window OpenboxWindow::createChildWindow(Window parent, Cursor cursor) { } return XCreateWindow(display, parent, 0, 0, 1, 1, 0, screen->getDepth(), - InputOutput, screen->getVisual(), create_mask, - &attrib_create); + InputOutput, screen->getVisual(), create_mask, + &attrib_create); } @@ -493,28 +498,28 @@ void OpenboxWindow::associateClientWindow(void) { XFlush(display); attrib_set.event_mask = PropertyChangeMask | StructureNotifyMask | - FocusChangeMask; + FocusChangeMask; attrib_set.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask | - ButtonMotionMask; + ButtonMotionMask; XChangeWindowAttributes(display, client.window, CWEventMask|CWDontPropagate, &attrib_set); #ifdef SHAPE - if (openbox->hasShapeExtensions()) { + if (openbox.hasShapeExtensions()) { XShapeSelectInput(display, client.window, ShapeNotifyMask); int foo; unsigned int ufoo; XShapeQueryExtents(display, client.window, &flags.shaped, &foo, &foo, - &ufoo, &ufoo, &foo, &foo, &foo, &ufoo, &ufoo); + &ufoo, &ufoo, &foo, &foo, &foo, &ufoo, &ufoo); if (flags.shaped) { XShapeCombineShape(display, frame.window, ShapeBounding, - frame.mwm_border_w, frame.y_border + - frame.mwm_border_w, client.window, - ShapeBounding, ShapeSet); + frame.mwm_border_w, frame.y_border + + frame.mwm_border_w, client.window, + ShapeBounding, ShapeSet); int num = 1; XRectangle xrect[2]; @@ -523,15 +528,15 @@ void OpenboxWindow::associateClientWindow(void) { xrect[0].height = frame.y_border; if (decorations.handle) { - xrect[1].x = 0; - xrect[1].y = frame.y_handle; - xrect[1].width = frame.width; - xrect[1].height = frame.handle_h + frame.border_w; - num++; + xrect[1].x = 0; + xrect[1].y = frame.y_handle; + xrect[1].width = frame.width; + xrect[1].height = frame.handle_h + frame.border_w; + num++; } XShapeCombineRectangles(display, frame.window, ShapeBounding, 0, 0, - xrect, num, ShapeUnion, Unsorted); + xrect, num, ShapeUnion, Unsorted); } } #endif // SHAPE @@ -539,24 +544,6 @@ void OpenboxWindow::associateClientWindow(void) { if (decorations.iconify) createIconifyButton(); if (decorations.maximize) createMaximizeButton(); if (decorations.close) createCloseButton(); - - if (frame.ubutton) { - if (frame.close_button) - XSetWindowBackgroundPixmap(display, frame.close_button, frame.ubutton); - if (frame.maximize_button) - XSetWindowBackgroundPixmap(display, frame.maximize_button, - frame.ubutton); - if (frame.iconify_button) - XSetWindowBackgroundPixmap(display, frame.iconify_button, frame.ubutton); - } else { - if (frame.close_button) - XSetWindowBackground(display, frame.close_button, frame.ubutton_pixel); - if (frame.maximize_button) - XSetWindowBackground(display, frame.maximize_button, - frame.ubutton_pixel); - if (frame.iconify_button) - XSetWindowBackground(display, frame.iconify_button, frame.ubutton_pixel); - } } @@ -719,7 +706,7 @@ void OpenboxWindow::decorateLabel(void) { void OpenboxWindow::createCloseButton(void) { if (decorations.close && frame.title != None) { frame.close_button = createChildWindow(frame.title); - openbox->saveWindowSearch(frame.close_button, this); + openbox.saveWindowSearch(frame.close_button, this); } } @@ -727,7 +714,7 @@ void OpenboxWindow::createCloseButton(void) { void OpenboxWindow::createIconifyButton(void) { if (decorations.iconify && frame.title != None) { frame.iconify_button = createChildWindow(frame.title); - openbox->saveWindowSearch(frame.iconify_button, this); + openbox.saveWindowSearch(frame.iconify_button, this); } } @@ -735,13 +722,13 @@ void OpenboxWindow::createIconifyButton(void) { void OpenboxWindow::createMaximizeButton(void) { if (decorations.maximize && frame.title != None) { frame.maximize_button = createChildWindow(frame.title); - openbox->saveWindowSearch(frame.maximize_button, this); + openbox.saveWindowSearch(frame.maximize_button, this); } } -void OpenboxWindow::positionButtons(Bool redecorate_label) { - const char *format = openbox->getTitleBarLayout(); +void OpenboxWindow::positionButtons() { + const char *format = openbox.getTitleBarLayout(); const unsigned int bw = frame.bevel_w + 1; const unsigned int by = frame.bevel_w + 1; unsigned int bx = frame.bevel_w + 1; @@ -754,44 +741,47 @@ void OpenboxWindow::positionButtons(Bool redecorate_label) { if (!decorations.iconify) bcount--; frame.label_w = frame.width - bx * 2 - (frame.button_w + bw) * bcount; - + bool hasclose, hasiconify, hasmaximize; hasclose = hasiconify = hasmaximize = false; - + for (int i = 0; format[i] != '\0' && i < 4; i++) { switch(format[i]) { case 'C': - if (decorations.close && frame.close_button != None) { + if (decorations.close) { + if (frame.close_button == None) + createCloseButton(); XMoveResizeWindow(display, frame.close_button, bx, by, frame.button_w, frame.button_h); XMapWindow(display, frame.close_button); XClearWindow(display, frame.close_button); bx += frame.button_w + bw; hasclose = true; - } else if (frame.close_button) - XUnmapWindow(display, frame.close_button); + } break; case 'I': - if (decorations.iconify && frame.iconify_button != None) { + if (decorations.iconify) { + if (frame.iconify_button == None) + createIconifyButton(); XMoveResizeWindow(display, frame.iconify_button, bx, by, frame.button_w, frame.button_h); XMapWindow(display, frame.iconify_button); XClearWindow(display, frame.iconify_button); bx += frame.button_w + bw; hasiconify = true; - } else if (frame.close_button) - XUnmapWindow(display, frame.close_button); + } break; case 'M': - if (decorations.maximize && frame.maximize_button != None) { + if (decorations.maximize) { + if (frame.maximize_button == None) + createMaximizeButton(); XMoveResizeWindow(display, frame.maximize_button, bx, by, frame.button_w, frame.button_h); XMapWindow(display, frame.maximize_button); XClearWindow(display, frame.maximize_button); bx += frame.button_w + bw; hasmaximize = true; - } else if (frame.close_button) - XUnmapWindow(display, frame.close_button); + } break; case 'L': XMoveResizeWindow(display, frame.label, bx, by - 1, @@ -801,20 +791,22 @@ void OpenboxWindow::positionButtons(Bool redecorate_label) { } } - if (!hasclose) { - openbox->removeWindowSearch(frame.close_button); - XDestroyWindow(display, frame.close_button); + if (!hasclose && frame.close_button) { + openbox.removeWindowSearch(frame.close_button); + XDestroyWindow(display, frame.close_button); + frame.close_button = None; } - if (!hasiconify) { - openbox->removeWindowSearch(frame.iconify_button); - XDestroyWindow(display, frame.iconify_button); + if (!hasiconify && frame.iconify_button) { + openbox.removeWindowSearch(frame.iconify_button); + XDestroyWindow(display, frame.iconify_button); + frame.iconify_button = None; } - if (!hasmaximize) { - openbox->removeWindowSearch(frame.maximize_button); - XDestroyWindow(display, frame.maximize_button); + if (!hasmaximize && frame.iconify_button) { + openbox.removeWindowSearch(frame.maximize_button); + XDestroyWindow(display, frame.maximize_button); + frame.maximize_button = None; } - if (redecorate_label) - decorateLabel(); + redrawLabel(); redrawAllButtons(); } @@ -825,17 +817,17 @@ void OpenboxWindow::reconfigure(void) { client.x = frame.x + frame.mwm_border_w + frame.border_w; client.y = frame.y + frame.y_border + frame.mwm_border_w + - frame.border_w; + frame.border_w; if (client.title) { - if (i18n->multibyte()) { + if (i18n.multibyte()) { XRectangle ink, logical; XmbTextExtents(screen->getWindowStyle()->fontset, - client.title, client.title_len, &ink, &logical); + client.title, client.title_len, &ink, &logical); client.title_text_w = logical.width; } else { client.title_text_w = XTextWidth(screen->getWindowStyle()->font, - client.title, client.title_len); + client.title, client.title_len); } client.title_text_w += (frame.bevel_w * 4); } @@ -848,16 +840,19 @@ void OpenboxWindow::reconfigure(void) { configure(frame.x, frame.y, frame.width, frame.height); - if (! screen->isSloppyFocus()) - openbox->grabButton(Button1, 0, frame.plate, True, ButtonPressMask, - GrabModeSync, GrabModeSync, None, None); + if (! screen->sloppyFocus()) + openbox.grabButton(Button1, 0, frame.plate, True, ButtonPressMask, + GrabModeSync, GrabModeSync, None, None); else - openbox->ungrabButton(Button1, 0, frame.plate); + openbox.ungrabButton(Button1, 0, frame.plate); if (windowmenu) { windowmenu->move(windowmenu->getX(), frame.y + frame.title_h); windowmenu->reconfigure(); } + + // re-get the timeout delay + timer->setTimeout(openbox.getAutoRaiseDelay()); } @@ -873,7 +868,7 @@ void OpenboxWindow::positionWindows(void) { if (decorations.titlebar) { XSetWindowBorderWidth(display, frame.title, frame.border_w); XMoveResizeWindow(display, frame.title, -frame.border_w, - -frame.border_w, frame.width, frame.title_h); + -frame.border_w, frame.width, frame.title_h); positionButtons(); } else if (frame.title) { @@ -886,11 +881,11 @@ void OpenboxWindow::positionWindows(void) { XMoveResizeWindow(display, frame.handle, -frame.border_w, frame.y_handle - frame.border_w, - frame.width, frame.handle_h); + frame.width, frame.handle_h); XMoveResizeWindow(display, frame.left_grip, -frame.border_w, - -frame.border_w, frame.grip_w, frame.grip_h); + -frame.border_w, frame.grip_w, frame.grip_h); XMoveResizeWindow(display, frame.right_grip, - frame.width - frame.grip_w - frame.border_w, + frame.width - frame.grip_w - frame.border_w, -frame.border_w, frame.grip_w, frame.grip_h); XMapSubwindows(display, frame.handle); } else if (frame.handle) { @@ -912,39 +907,39 @@ void OpenboxWindow::getWMName(void) { if (XGetWMName(display, client.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) { - client.title = bstrdup(*list); - XFreeStringList(list); - } else { - client.title = bstrdup((char *) text_prop.value); - } + text_prop.nitems = strlen((char *) text_prop.value); + + if ((XmbTextPropertyToTextList(display, &text_prop, + &list, &num) == Success) && + (num > 0) && *list) { + client.title = bstrdup(*list); + XFreeStringList(list); + } else { + client.title = bstrdup((char *) text_prop.value); + } } else { - client.title = bstrdup((char *) text_prop.value); + client.title = bstrdup((char *) text_prop.value); } XFree((char *) text_prop.value); } else { - client.title = bstrdup(i18n->getMessage(WindowSet, WindowUnnamed, - "Unnamed")); + client.title = bstrdup(i18n(WindowSet, WindowUnnamed, + "Unnamed")); } } else { - client.title = bstrdup(i18n->getMessage(WindowSet, WindowUnnamed, - "Unnamed")); + client.title = bstrdup(i18n(WindowSet, WindowUnnamed, + "Unnamed")); } client.title_len = strlen(client.title); - if (i18n->multibyte()) { + if (i18n.multibyte()) { XRectangle ink, logical; XmbTextExtents(screen->getWindowStyle()->fontset, - client.title, client.title_len, &ink, &logical); + client.title, client.title_len, &ink, &logical); client.title_text_w = logical.width; } else { client.title_len = strlen(client.title); client.title_text_w = XTextWidth(screen->getWindowStyle()->font, - client.title, client.title_len); + client.title, client.title_len); } client.title_text_w += (frame.bevel_w * 4); @@ -964,18 +959,18 @@ void OpenboxWindow::getWMIconName(void) { if (XGetWMIconName(display, client.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) { - client.icon_title = bstrdup(*list); - XFreeStringList(list); - } else { - client.icon_title = bstrdup((char *) text_prop.value); - } + text_prop.nitems = strlen((char *) text_prop.value); + + if ((XmbTextPropertyToTextList(display, &text_prop, + &list, &num) == Success) && + (num > 0) && *list) { + client.icon_title = bstrdup(*list); + XFreeStringList(list); + } else { + client.icon_title = bstrdup((char *) text_prop.value); + } } else { - client.icon_title = bstrdup((char *) text_prop.value); + client.icon_title = bstrdup((char *) text_prop.value); } XFree((char *) text_prop.value); } else { @@ -1000,12 +995,12 @@ void OpenboxWindow::getWMProtocols(void) { if (XGetWMProtocols(display, client.window, &proto, &num_return)) { for (int i = 0; i < num_return; ++i) { - if (proto[i] == openbox->getWMDeleteAtom()) - functions.close = decorations.close = True; - else if (proto[i] == openbox->getWMTakeFocusAtom()) + if (proto[i] == openbox.getWMDeleteAtom()) + functions.close = decorations.close = True; + else if (proto[i] == openbox.getWMTakeFocusAtom()) flags.send_focus_message = True; - else if (proto[i] == openbox->getOpenboxStructureMessagesAtom()) - screen->addNetizen(new Netizen(screen, client.window)); + else if (proto[i] == openbox.getOpenboxStructureMessagesAtom()) + screen->addNetizen(new Netizen(*screen, client.window)); } XFree(proto); @@ -1031,14 +1026,14 @@ void OpenboxWindow::getWMHints(void) { if (wmhint->flags & InputHint) { if (wmhint->input == True) { if (flags.send_focus_message) - focus_mode = F_LocallyActive; + focus_mode = F_LocallyActive; else - focus_mode = F_Passive; + focus_mode = F_Passive; } else { if (flags.send_focus_message) - focus_mode = F_GloballyActive; + focus_mode = F_GloballyActive; else - focus_mode = F_NoInput; + focus_mode = F_NoInput; } } else { focus_mode = F_Passive; @@ -1052,7 +1047,7 @@ void OpenboxWindow::getWMHints(void) { if (wmhint->flags & WindowGroupHint) { if (! client.window_group) { client.window_group = wmhint->window_group; - openbox->saveGroupSearch(client.window_group, this); + openbox.saveGroupSearch(client.window_group, this); } } else { client.window_group = None; @@ -1072,8 +1067,8 @@ void OpenboxWindow::getWMNormalHints(void) { client.min_width = client.min_height = client.base_width = client.base_height = client.width_inc = client.height_inc = 1; - client.max_width = screen->getWidth(); - client.max_height = screen->getHeight(); + client.max_width = screen->size().w(); + client.max_height = screen->size().h(); client.min_aspect_x = client.min_aspect_y = client.max_aspect_x = client.max_aspect_y = 1; client.win_gravity = NorthWestGravity; @@ -1128,11 +1123,11 @@ void OpenboxWindow::getMWMHints(void) { unsigned long num, len; int ret = XGetWindowProperty(display, client.window, - openbox->getMotifWMHintsAtom(), 0, - PropMwmHintsElements, False, - openbox->getMotifWMHintsAtom(), &atom_return, - &format, &num, &len, - (unsigned char **) &client.mwm_hint); + openbox.getMotifWMHintsAtom(), 0, + PropMwmHintsElements, False, + openbox.getMotifWMHintsAtom(), &atom_return, + &format, &num, &len, + (unsigned char **) &client.mwm_hint); if (ret != Success || !client.mwm_hint || num != PropMwmHintsElements) return; @@ -1140,46 +1135,46 @@ void OpenboxWindow::getMWMHints(void) { if (client.mwm_hint->flags & MwmHintsDecorations) { if (client.mwm_hint->decorations & MwmDecorAll) { decorations.titlebar = decorations.handle = decorations.border = - decorations.iconify = decorations.maximize = - decorations.close = decorations.menu = True; + decorations.iconify = decorations.maximize = + decorations.close = decorations.menu = True; } else { decorations.titlebar = decorations.handle = decorations.border = - decorations.iconify = decorations.maximize = - decorations.close = decorations.menu = False; + decorations.iconify = decorations.maximize = + decorations.close = decorations.menu = False; if (client.mwm_hint->decorations & MwmDecorBorder) - decorations.border = True; + decorations.border = True; if (client.mwm_hint->decorations & MwmDecorHandle) - decorations.handle = True; + decorations.handle = True; if (client.mwm_hint->decorations & MwmDecorTitle) - decorations.titlebar = True; + decorations.titlebar = True; if (client.mwm_hint->decorations & MwmDecorMenu) - decorations.menu = True; + decorations.menu = True; if (client.mwm_hint->decorations & MwmDecorIconify) - decorations.iconify = True; + decorations.iconify = True; if (client.mwm_hint->decorations & MwmDecorMaximize) - decorations.maximize = True; + decorations.maximize = True; } } if (client.mwm_hint->flags & MwmHintsFunctions) { if (client.mwm_hint->functions & MwmFuncAll) { functions.resize = functions.move = functions.iconify = - functions.maximize = functions.close = True; + functions.maximize = functions.close = True; } else { functions.resize = functions.move = functions.iconify = - functions.maximize = functions.close = False; + functions.maximize = functions.close = False; if (client.mwm_hint->functions & MwmFuncResize) - functions.resize = True; + functions.resize = True; if (client.mwm_hint->functions & MwmFuncMove) - functions.move = True; + functions.move = True; if (client.mwm_hint->functions & MwmFuncIconify) - functions.iconify = True; + functions.iconify = True; if (client.mwm_hint->functions & MwmFuncMaximize) - functions.maximize = True; + functions.maximize = True; if (client.mwm_hint->functions & MwmFuncClose) - functions.close = True; + functions.close = True; } } } @@ -1198,11 +1193,11 @@ void OpenboxWindow::getOpenboxHints(void) { unsigned long num, len; int ret = XGetWindowProperty(display, client.window, - openbox->getOpenboxHintsAtom(), 0, - PropOpenboxHintsElements, False, - openbox->getOpenboxHintsAtom(), &atom_return, - &format, &num, &len, - (unsigned char **) &client.openbox_hint); + openbox.getOpenboxHintsAtom(), 0, + PropOpenboxHintsElements, False, + openbox.getOpenboxHintsAtom(), &atom_return, + &format, &num, &len, + (unsigned char **) &client.openbox_hint); if (ret != Success || !client.openbox_hint || num != PropOpenboxHintsElements) return; @@ -1213,7 +1208,7 @@ void OpenboxWindow::getOpenboxHints(void) { if ((client.openbox_hint->flags & AttribMaxHoriz) && (client.openbox_hint->flags & AttribMaxVert)) flags.maximized = (client.openbox_hint->attrib & - (AttribMaxHoriz | AttribMaxVert)) ? 1 : 0; + (AttribMaxHoriz | AttribMaxVert)) ? 1 : 0; else if (client.openbox_hint->flags & AttribMaxVert) flags.maximized = (client.openbox_hint->attrib & AttribMaxVert) ? 2 : 0; else if (client.openbox_hint->flags & AttribMaxHoriz) @@ -1233,36 +1228,36 @@ void OpenboxWindow::getOpenboxHints(void) { switch (client.openbox_hint->decoration) { case DecorNone: decorations.titlebar = decorations.border = decorations.handle = - decorations.iconify = decorations.maximize = - decorations.menu = False; + decorations.iconify = decorations.maximize = + decorations.menu = False; functions.resize = functions.move = functions.iconify = - functions.maximize = False; + functions.maximize = False; break; case DecorTiny: decorations.titlebar = decorations.iconify = decorations.menu = - functions.move = functions.iconify = True; + functions.move = functions.iconify = True; decorations.border = decorations.handle = decorations.maximize = - functions.resize = functions.maximize = False; + functions.resize = functions.maximize = False; break; case DecorTool: decorations.titlebar = decorations.menu = functions.move = True; decorations.iconify = decorations.border = decorations.handle = - decorations.maximize = functions.resize = functions.maximize = - functions.iconify = False; + decorations.maximize = functions.resize = functions.maximize = + functions.iconify = False; break; case DecorNormal: default: decorations.titlebar = decorations.border = decorations.handle = - decorations.iconify = decorations.maximize = - decorations.menu = True; + decorations.iconify = decorations.maximize = + decorations.menu = True; functions.resize = functions.move = functions.iconify = - functions.maximize = True; + functions.maximize = True; break; } @@ -1273,7 +1268,7 @@ void OpenboxWindow::getOpenboxHints(void) { void OpenboxWindow::configure(int dx, int dy, - unsigned int dw, unsigned int dh) { + unsigned int dw, unsigned int dh) { Bool send_event = (frame.x != dx || frame.y != dy); if ((dw != frame.width) || (dh != frame.height)) { @@ -1288,11 +1283,11 @@ void OpenboxWindow::configure(int dx, int dy, downsize(); #ifdef SHAPE - if (openbox->hasShapeExtensions() && flags.shaped) { + if (openbox.hasShapeExtensions() && flags.shaped) { XShapeCombineShape(display, frame.window, ShapeBounding, - frame.mwm_border_w, frame.y_border + - frame.mwm_border_w, client.window, - ShapeBounding, ShapeSet); + frame.mwm_border_w, frame.y_border + + frame.mwm_border_w, client.window, + ShapeBounding, ShapeSet); int num = 1; XRectangle xrect[2]; @@ -1301,24 +1296,23 @@ void OpenboxWindow::configure(int dx, int dy, xrect[0].height = frame.y_border; if (decorations.handle) { - xrect[1].x = 0; - xrect[1].y = frame.y_handle; - xrect[1].width = frame.width; - xrect[1].height = frame.handle_h + frame.border_w; - num++; + xrect[1].x = 0; + xrect[1].y = frame.y_handle; + xrect[1].width = frame.width; + xrect[1].height = frame.handle_h + frame.border_w; + num++; } XShapeCombineRectangles(display, frame.window, ShapeBounding, 0, 0, - xrect, num, ShapeUnion, Unsorted); + xrect, num, ShapeUnion, Unsorted); } #endif // SHAPE XMoveWindow(display, frame.window, frame.x, frame.y); + setFocusFlag(flags.focused); positionWindows(); decorate(); - setFocusFlag(flags.focused); - redrawAllButtons(); } else { frame.x = dx; frame.y = dy; @@ -1331,7 +1325,7 @@ void OpenboxWindow::configure(int dx, int dy, if (send_event && ! flags.moving) { client.x = dx + frame.mwm_border_w + frame.border_w; client.y = dy + frame.y_border + frame.mwm_border_w + - frame.border_w; + frame.border_w; XEvent event; event.type = ConfigureNotify; @@ -1354,67 +1348,64 @@ void OpenboxWindow::configure(int dx, int dy, } -Bool OpenboxWindow::setInputFocus(void) { +bool OpenboxWindow::setInputFocus(void) { if (((signed) (frame.x + frame.width)) < 0) { if (((signed) (frame.y + frame.y_border)) < 0) configure(frame.border_w, frame.border_w, frame.width, frame.height); - else if (frame.y > (signed) screen->getHeight()) - configure(frame.border_w, screen->getHeight() - frame.height, + else if (frame.y > (signed) screen->size().h()) + configure(frame.border_w, screen->size().h() - frame.height, frame.width, frame.height); else configure(frame.border_w, frame.y + frame.border_w, frame.width, frame.height); - } else if (frame.x > (signed) screen->getWidth()) { + } else if (frame.x > (signed) screen->size().w()) { if (((signed) (frame.y + frame.y_border)) < 0) - configure(screen->getWidth() - frame.width, frame.border_w, + configure(screen->size().w() - frame.width, frame.border_w, frame.width, frame.height); - else if (frame.y > (signed) screen->getHeight()) - configure(screen->getWidth() - frame.width, - screen->getHeight() - frame.height, frame.width, frame.height); + else if (frame.y > (signed) screen->size().h()) + configure(screen->size().w() - frame.width, + screen->size().h() - frame.height, frame.width, frame.height); else - configure(screen->getWidth() - frame.width, + configure(screen->size().w() - frame.width, frame.y + frame.border_w, frame.width, frame.height); } - openbox->grab(); + openbox.grab(); if (! validateClient()) return False; - Bool ret = False; + bool ret = false; if (client.transient && flags.modal) { ret = client.transient->setInputFocus(); } else if (! flags.focused) { - if (focus_mode == F_LocallyActive || focus_mode == F_Passive) + if (focus_mode == F_LocallyActive || focus_mode == F_Passive) { XSetInputFocus(display, client.window, - RevertToPointerRoot, CurrentTime); - else - XSetInputFocus(display, screen->getRootWindow(), - RevertToNone, CurrentTime); - - openbox->setFocusedWindow(this); - - if (flags.send_focus_message) { - XEvent ce; - ce.xclient.type = ClientMessage; - ce.xclient.message_type = openbox->getWMProtocolsAtom(); - ce.xclient.display = display; - ce.xclient.window = client.window; - ce.xclient.format = 32; - ce.xclient.data.l[0] = openbox->getWMTakeFocusAtom(); - ce.xclient.data.l[1] = openbox->getLastTime(); - ce.xclient.data.l[2] = 0l; - ce.xclient.data.l[3] = 0l; - ce.xclient.data.l[4] = 0l; - XSendEvent(display, client.window, False, NoEventMask, &ce); - } + RevertToPointerRoot, CurrentTime); + openbox.focusWindow(this); + + if (flags.send_focus_message) { + XEvent ce; + ce.xclient.type = ClientMessage; + ce.xclient.message_type = openbox.getWMProtocolsAtom(); + ce.xclient.display = display; + ce.xclient.window = client.window; + ce.xclient.format = 32; + ce.xclient.data.l[0] = openbox.getWMTakeFocusAtom(); + ce.xclient.data.l[1] = openbox.getLastTime(); + ce.xclient.data.l[2] = 0l; + ce.xclient.data.l[3] = 0l; + ce.xclient.data.l[4] = 0l; + XSendEvent(display, client.window, False, NoEventMask, &ce); + } - if (screen->isSloppyFocus() && screen->doAutoRaise()) - timer->start(); + if (screen->sloppyFocus() && screen->autoRaise()) + timer->start(); - ret = True; + ret = true; + } } - openbox->ungrab(); + openbox.ungrab(); return ret; } @@ -1423,6 +1414,9 @@ Bool OpenboxWindow::setInputFocus(void) { void OpenboxWindow::iconify(void) { if (flags.iconic) return; + if (flags.moving) + endMove(); + if (windowmenu) windowmenu->hide(); setState(IconicState); @@ -1450,7 +1444,7 @@ void OpenboxWindow::iconify(void) { } -void OpenboxWindow::deiconify(Bool reassoc, Bool raise) { +void OpenboxWindow::deiconify(bool reassoc, bool raise, bool initial) { if (flags.iconic || reassoc) screen->reassociateWindow(this, -1, False); else if (workspace_number != screen->getCurrentWorkspace()->getWorkspaceID()) @@ -1466,7 +1460,19 @@ void OpenboxWindow::deiconify(Bool reassoc, Bool raise) { XMapSubwindows(display, frame.window); XMapWindow(display, frame.window); - if (flags.iconic && screen->doFocusNew()) setInputFocus(); + // if we're using the click to place placement type, then immediately + // after the window is mapped, we need to start interactively moving it + if (initial && place_window && + screen->placementPolicy() == BScreen::ClickMousePlacement) { + int x, y, rx, ry; + Window c, r; + unsigned int m; + XQueryPointer(openbox.getXDisplay(), screen->getRootWindow(), + &r, &c, &rx, &ry, &x, &y, &m); + startMove(rx, ry); + } + + if (flags.iconic && screen->focusNew()) setInputFocus(); flags.visible = True; flags.iconic = False; @@ -1481,11 +1487,11 @@ void OpenboxWindow::deiconify(Bool reassoc, Bool raise) { void OpenboxWindow::close(void) { XEvent ce; ce.xclient.type = ClientMessage; - ce.xclient.message_type = openbox->getWMProtocolsAtom(); + ce.xclient.message_type = openbox.getWMProtocolsAtom(); ce.xclient.display = display; ce.xclient.window = client.window; ce.xclient.format = 32; - ce.xclient.data.l[0] = openbox->getWMDeleteAtom(); + ce.xclient.data.l[0] = openbox.getWMDeleteAtom(); ce.xclient.data.l[1] = CurrentTime; ce.xclient.data.l[2] = 0l; ce.xclient.data.l[3] = 0l; @@ -1495,6 +1501,9 @@ void OpenboxWindow::close(void) { void OpenboxWindow::withdraw(void) { + if (flags.moving) + endMove(); + flags.visible = False; flags.iconic = False; @@ -1510,6 +1519,9 @@ void OpenboxWindow::withdraw(void) { void OpenboxWindow::maximize(unsigned int button) { + if (flags.moving) + endMove(); + // handle case where menu is open then the max button is used instead if (windowmenu && windowmenu->isVisible()) windowmenu->hide(); @@ -1524,39 +1536,34 @@ void OpenboxWindow::maximize(unsigned int button) { // so we do not need to call configure() because resizing will handle it if (!flags.resizing) configure(openbox_attrib.premax_x, openbox_attrib.premax_y, - openbox_attrib.premax_w, openbox_attrib.premax_h); + openbox_attrib.premax_w, openbox_attrib.premax_h); openbox_attrib.premax_x = openbox_attrib.premax_y = 0; openbox_attrib.premax_w = openbox_attrib.premax_h = 0; - redrawAllButtons(); + redrawMaximizeButton(flags.maximized); setState(current_state); return; } - int dx = 0, dy = 0; - unsigned int dw, dh; - openbox_attrib.premax_x = frame.x; openbox_attrib.premax_y = frame.y; openbox_attrib.premax_w = frame.width; openbox_attrib.premax_h = frame.height; - dw = screen->getWidth(); + Rect space = screen->availableArea(); + unsigned int dw = space.w(), + dh = space.h(); dw -= frame.border_w * 2; dw -= frame.mwm_border_w * 2; dw -= client.base_width; - dh = screen->getHeight(); dh -= frame.border_w * 2; dh -= frame.mwm_border_w * 2; dh -= ((frame.handle_h + frame.border_w) * decorations.handle); dh -= client.base_height; dh -= frame.y_border; - if (! screen->doFullMax()) - dh -= screen->getToolbar()->getExposedHeight() + frame.border_w; - if (dw < client.min_width) dw = client.min_width; if (dh < client.min_height) dh = client.min_height; if (dw > client.max_width) dw = client.max_width; @@ -1572,23 +1579,8 @@ void OpenboxWindow::maximize(unsigned int button) { dh += ((frame.handle_h + frame.border_w) * decorations.handle); dh += frame.mwm_border_w * 2; - dx += ((screen->getWidth() - dw) / 2) - frame.border_w; - - if (screen->doFullMax()) { - dy += ((screen->getHeight() - dh) / 2) - frame.border_w; - } else { - dy += (((screen->getHeight() - screen->getToolbar()->getExposedHeight()) - - dh) / 2) - frame.border_w; - - switch (screen->getToolbarPlacement()) { - case Toolbar::TopLeft: - case Toolbar::TopCenter: - case Toolbar::TopRight: - dy += screen->getToolbar()->getExposedHeight() + - frame.border_w; - break; - } - } + int dx = space.x() + ((space.w() - dw) / 2) - frame.border_w, + dy = space.y() + ((space.h() - dh) / 2) - frame.border_w; switch(button) { case 1: @@ -1623,12 +1615,13 @@ void OpenboxWindow::maximize(unsigned int button) { configure(dx, dy, dw, dh); screen->getWorkspace(workspace_number)->raiseWindow(this); - redrawAllButtons(); + redrawMaximizeButton(flags.maximized); setState(current_state); } void OpenboxWindow::setWorkspace(int n) { + ASSERT(n < screen->getWorkspaceCount()); workspace_number = n; openbox_attrib.flags |= AttribWorkspace; @@ -1741,13 +1734,14 @@ void OpenboxWindow::setFocusFlag(Bool focus) { XSetWindowBorder(display, frame.plate, frame.uborder_pixel); } - if (screen->isSloppyFocus() && screen->doAutoRaise() && timer->isTiming()) + if (screen->sloppyFocus() && screen->autoRaise() && timer->isTiming()) timer->stop(); + } void OpenboxWindow::installColormap(Bool install) { - openbox->grab(); + openbox.grab(); if (! validateClient()) return; int i = 0, ncmap = 0; @@ -1756,29 +1750,29 @@ void OpenboxWindow::installColormap(Bool install) { if (cmaps) { if (XGetWindowAttributes(display, client.window, &wattrib)) { if (install) { - // install the window's colormap - for (i = 0; i < ncmap; i++) { - if (*(cmaps + i) == wattrib.colormap) - // this window is using an installed color map... do not install - install = False; - } - // otherwise, install the window's colormap - if (install) - XInstallColormap(display, wattrib.colormap); + // install the window's colormap + for (i = 0; i < ncmap; i++) { + if (*(cmaps + i) == wattrib.colormap) + // this window is using an installed color map... do not install + install = False; + } + // otherwise, install the window's colormap + if (install) + XInstallColormap(display, wattrib.colormap); } else { - // uninstall the window's colormap - for (i = 0; i < ncmap; i++) { - if (*(cmaps + i) == wattrib.colormap) - // we found the colormap to uninstall - XUninstallColormap(display, wattrib.colormap); - } + // uninstall the window's colormap + for (i = 0; i < ncmap; i++) { + if (*(cmaps + i) == wattrib.colormap) + // we found the colormap to uninstall + XUninstallColormap(display, wattrib.colormap); + } } } XFree(cmaps); } - openbox->ungrab(); + openbox.ungrab(); } @@ -1788,15 +1782,15 @@ void OpenboxWindow::setState(unsigned long new_state) { unsigned long state[2]; state[0] = (unsigned long) current_state; state[1] = (unsigned long) None; - XChangeProperty(display, client.window, openbox->getWMStateAtom(), - openbox->getWMStateAtom(), 32, PropModeReplace, - (unsigned char *) state, 2); + XChangeProperty(display, client.window, openbox.getWMStateAtom(), + openbox.getWMStateAtom(), 32, PropModeReplace, + (unsigned char *) state, 2); XChangeProperty(display, client.window, - openbox->getOpenboxAttributesAtom(), - openbox->getOpenboxAttributesAtom(), 32, PropModeReplace, + openbox.getOpenboxAttributesAtom(), + openbox.getOpenboxAttributesAtom(), 32, PropModeReplace, (unsigned char *) &openbox_attrib, - PropOpenboxAttributesElements); + PropOpenboxAttributesElements); } @@ -1808,12 +1802,12 @@ Bool OpenboxWindow::getState(void) { int foo; unsigned long *state, ulfoo, nitems; - if ((XGetWindowProperty(display, client.window, openbox->getWMStateAtom(), - 0l, 2l, False, openbox->getWMStateAtom(), - &atom_return, &foo, &nitems, &ulfoo, - (unsigned char **) &state) != Success) || + if ((XGetWindowProperty(display, client.window, openbox.getWMStateAtom(), + 0l, 2l, False, openbox.getWMStateAtom(), + &atom_return, &foo, &nitems, &ulfoo, + (unsigned char **) &state) != Success) || (! state)) { - openbox->ungrab(); + openbox.ungrab(); return False; } @@ -1895,11 +1889,11 @@ void OpenboxWindow::restoreAttributes(void) { OpenboxAttributes *net; int ret = XGetWindowProperty(display, client.window, - openbox->getOpenboxAttributesAtom(), 0l, - PropOpenboxAttributesElements, False, - openbox->getOpenboxAttributesAtom(), - &atom_return, &foo, &nitems, &ulfoo, - (unsigned char **) &net); + openbox.getOpenboxAttributesAtom(), 0l, + PropOpenboxAttributesElements, False, + openbox.getOpenboxAttributesAtom(), + &atom_return, &foo, &nitems, &ulfoo, + (unsigned char **) &net); if (ret != Success || !net || nitems != PropOpenboxAttributesElements) return; @@ -2051,18 +2045,18 @@ void OpenboxWindow::redrawLabel(void) { if (client.title_text_w > frame.label_w) { for (; dlen >= 0; dlen--) { - if (i18n->multibyte()) { - XRectangle ink, logical; - XmbTextExtents(screen->getWindowStyle()->fontset, client.title, dlen, - &ink, &logical); - l = logical.width; + if (i18n.multibyte()) { + XRectangle ink, logical; + XmbTextExtents(screen->getWindowStyle()->fontset, client.title, dlen, + &ink, &logical); + l = logical.width; } else { - l = XTextWidth(screen->getWindowStyle()->font, client.title, dlen); + l = XTextWidth(screen->getWindowStyle()->font, client.title, dlen); } l += (frame.bevel_w * 4); if (l < frame.label_w) - break; + break; } } @@ -2079,13 +2073,13 @@ void OpenboxWindow::redrawLabel(void) { WindowStyle *style = screen->getWindowStyle(); GC text_gc = (flags.focused) ? style->l_text_focus_gc : style->l_text_unfocus_gc; - if (i18n->multibyte()) + if (i18n.multibyte()) XmbDrawString(display, frame.label, style->fontset, text_gc, dx, - (1 - style->fontset_extents->max_ink_extent.y), - client.title, dlen); + (1 - style->fontset_extents->max_ink_extent.y), + client.title, dlen); else XDrawString(display, frame.label, text_gc, dx, - (style->font->ascent + 1), client.title, dlen); + (style->font->ascent + 1), client.title, dlen); } @@ -2101,17 +2095,17 @@ void OpenboxWindow::redrawIconifyButton(Bool pressed) { if (flags.focused) { if (frame.fbutton) XSetWindowBackgroundPixmap(display, frame.iconify_button, - frame.fbutton); + frame.fbutton); else XSetWindowBackground(display, frame.iconify_button, - frame.fbutton_pixel); + frame.fbutton_pixel); } else { if (frame.ubutton) XSetWindowBackgroundPixmap(display, frame.iconify_button, - frame.ubutton); + frame.ubutton); else XSetWindowBackground(display, frame.iconify_button, - frame.ubutton_pixel); + frame.ubutton_pixel); } } else { if (frame.pbutton) @@ -2122,9 +2116,9 @@ void OpenboxWindow::redrawIconifyButton(Bool pressed) { XClearWindow(display, frame.iconify_button); XDrawRectangle(display, frame.iconify_button, - ((flags.focused) ? screen->getWindowStyle()->b_pic_focus_gc : - screen->getWindowStyle()->b_pic_unfocus_gc), - 2, (frame.button_h - 5), (frame.button_w - 5), 2); + ((flags.focused) ? screen->getWindowStyle()->b_pic_focus_gc : + screen->getWindowStyle()->b_pic_unfocus_gc), + 2, (frame.button_h - 5), (frame.button_w - 5), 2); } @@ -2133,36 +2127,36 @@ void OpenboxWindow::redrawMaximizeButton(Bool pressed) { if (flags.focused) { if (frame.fbutton) XSetWindowBackgroundPixmap(display, frame.maximize_button, - frame.fbutton); + frame.fbutton); else XSetWindowBackground(display, frame.maximize_button, - frame.fbutton_pixel); + frame.fbutton_pixel); } else { if (frame.ubutton) XSetWindowBackgroundPixmap(display, frame.maximize_button, - frame.ubutton); + frame.ubutton); else XSetWindowBackground(display, frame.maximize_button, - frame.ubutton_pixel); + frame.ubutton_pixel); } } else { if (frame.pbutton) XSetWindowBackgroundPixmap(display, frame.maximize_button, - frame.pbutton); + frame.pbutton); else XSetWindowBackground(display, frame.maximize_button, - frame.pbutton_pixel); + frame.pbutton_pixel); } XClearWindow(display, frame.maximize_button); XDrawRectangle(display, frame.maximize_button, - ((flags.focused) ? screen->getWindowStyle()->b_pic_focus_gc : - screen->getWindowStyle()->b_pic_unfocus_gc), - 2, 2, (frame.button_w - 5), (frame.button_h - 5)); + ((flags.focused) ? screen->getWindowStyle()->b_pic_focus_gc : + screen->getWindowStyle()->b_pic_unfocus_gc), + 2, 2, (frame.button_w - 5), (frame.button_h - 5)); XDrawLine(display, frame.maximize_button, - ((flags.focused) ? screen->getWindowStyle()->b_pic_focus_gc : - screen->getWindowStyle()->b_pic_unfocus_gc), - 2, 3, (frame.button_w - 3), 3); + ((flags.focused) ? screen->getWindowStyle()->b_pic_focus_gc : + screen->getWindowStyle()->b_pic_unfocus_gc), + 2, 3, (frame.button_w - 3), 3); } @@ -2171,17 +2165,17 @@ void OpenboxWindow::redrawCloseButton(Bool pressed) { if (flags.focused) { if (frame.fbutton) XSetWindowBackgroundPixmap(display, frame.close_button, - frame.fbutton); + frame.fbutton); else XSetWindowBackground(display, frame.close_button, - frame.fbutton_pixel); + frame.fbutton_pixel); } else { if (frame.ubutton) XSetWindowBackgroundPixmap(display, frame.close_button, - frame.ubutton); + frame.ubutton); else XSetWindowBackground(display, frame.close_button, - frame.ubutton_pixel); + frame.ubutton_pixel); } } else { if (frame.pbutton) @@ -2192,13 +2186,13 @@ void OpenboxWindow::redrawCloseButton(Bool pressed) { XClearWindow(display, frame.close_button); XDrawLine(display, frame.close_button, - ((flags.focused) ? screen->getWindowStyle()->b_pic_focus_gc : - screen->getWindowStyle()->b_pic_unfocus_gc), 2, 2, + ((flags.focused) ? screen->getWindowStyle()->b_pic_focus_gc : + screen->getWindowStyle()->b_pic_unfocus_gc), 2, 2, (frame.button_w - 3), (frame.button_h - 3)); XDrawLine(display, frame.close_button, - ((flags.focused) ? screen->getWindowStyle()->b_pic_focus_gc : - screen->getWindowStyle()->b_pic_unfocus_gc), 2, - (frame.button_h - 3), + ((flags.focused) ? screen->getWindowStyle()->b_pic_focus_gc : + screen->getWindowStyle()->b_pic_unfocus_gc), 2, + (frame.button_h - 3), (frame.button_w - 3), 2); } @@ -2206,16 +2200,16 @@ void OpenboxWindow::redrawCloseButton(Bool pressed) { void OpenboxWindow::mapRequestEvent(XMapRequestEvent *re) { if (re->window == client.window) { #ifdef DEBUG - fprintf(stderr, i18n->getMessage(WindowSet, WindowMapRequest, - "OpenboxWindow::mapRequestEvent() for 0x%lx\n"), + fprintf(stderr, i18n(WindowSet, WindowMapRequest, + "OpenboxWindow::mapRequestEvent() for 0x%lx\n"), client.window); #endif // DEBUG - openbox->grab(); + openbox.grab(); if (! validateClient()) return; Bool get_state_ret = getState(); - if (! (get_state_ret && openbox->isStartup())) { + if (! (get_state_ret && openbox.isStartup())) { if ((client.wm_hint_flags & StateHint) && (! (current_state == NormalState || current_state == IconicState))) current_state = client.initial_state; @@ -2238,11 +2232,12 @@ void OpenboxWindow::mapRequestEvent(XMapRequestEvent *re) { case InactiveState: case ZoomState: default: - deiconify(False); + deiconify(False, True, True); // specify that we're initializing the + // window break; } - openbox->ungrab(); + openbox.ungrab(); } } @@ -2250,16 +2245,12 @@ void OpenboxWindow::mapRequestEvent(XMapRequestEvent *re) { void OpenboxWindow::mapNotifyEvent(XMapEvent *ne) { if ((ne->window == client.window) && (! ne->override_redirect) && (flags.visible)) { - openbox->grab(); + openbox.grab(); if (! validateClient()) return; - if (decorations.titlebar) positionButtons(); - setState(NormalState); - redrawAllButtons(); - - if (flags.transient || screen->doFocusNew()) + if (flags.transient || screen->focusNew()) setInputFocus(); else setFocusFlag(False); @@ -2267,7 +2258,7 @@ void OpenboxWindow::mapNotifyEvent(XMapEvent *ne) { flags.visible = True; flags.iconic = False; - openbox->ungrab(); + openbox.ungrab(); } } @@ -2275,41 +2266,44 @@ void OpenboxWindow::mapNotifyEvent(XMapEvent *ne) { void OpenboxWindow::unmapNotifyEvent(XUnmapEvent *ue) { if (ue->window == client.window) { #ifdef DEBUG - fprintf(stderr, i18n->getMessage(WindowSet, WindowUnmapNotify, - "OpenboxWindow::unmapNotifyEvent() for 0x%lx\n"), + fprintf(stderr, i18n(WindowSet, WindowUnmapNotify, + "OpenboxWindow::unmapNotifyEvent() for 0x%lx\n"), client.window); #endif // DEBUG - openbox->grab(); + openbox.grab(); if (! validateClient()) return; + if (flags.moving) + endMove(); + XChangeSaveSet(display, client.window, SetModeDelete); XSelectInput(display, client.window, NoEventMask); - XDeleteProperty(display, client.window, openbox->getWMStateAtom()); + XDeleteProperty(display, client.window, openbox.getWMStateAtom()); XDeleteProperty(display, client.window, - openbox->getOpenboxAttributesAtom()); + openbox.getOpenboxAttributesAtom()); XUnmapWindow(display, frame.window); XUnmapWindow(display, client.window); XEvent dummy; if (! XCheckTypedWindowEvent(display, client.window, ReparentNotify, - &dummy)) { + &dummy)) { #ifdef DEBUG - fprintf(stderr, i18n->getMessage(WindowSet, WindowUnmapNotifyReparent, - "OpenboxWindow::unmapNotifyEvent(): reparent 0x%lx to " - "root.\n"), client.window); + fprintf(stderr, i18n(WindowSet, WindowUnmapNotifyReparent, + "OpenboxWindow::unmapNotifyEvent(): reparent 0x%lx to " + "root.\n"), client.window); #endif // DEBUG restoreGravity(); XReparentWindow(display, client.window, screen->getRootWindow(), - client.x, client.y); + client.x, client.y); } XFlush(display); - openbox->ungrab(); + openbox.ungrab(); delete this; } @@ -2318,6 +2312,8 @@ void OpenboxWindow::unmapNotifyEvent(XUnmapEvent *ue) { void OpenboxWindow::destroyNotifyEvent(XDestroyWindowEvent *de) { if (de->window == client.window) { + if (flags.moving) + endMove(); XUnmapWindow(display, frame.window); delete this; @@ -2326,7 +2322,7 @@ void OpenboxWindow::destroyNotifyEvent(XDestroyWindowEvent *de) { void OpenboxWindow::propertyNotifyEvent(Atom atom) { - openbox->grab(); + openbox.grab(); if (! validateClient()) return; switch(atom) { @@ -2340,13 +2336,13 @@ void OpenboxWindow::propertyNotifyEvent(Atom atom) { Window win; if (XGetTransientForHint(display, client.window, &win)) { if (win && (win != client.window)) { - if ((client.transient_for = openbox->searchWindow(win))) { + if ((client.transient_for = openbox.searchWindow(win))) { client.transient_for->client.transient = this; flags.stuck = client.transient_for->flags.stuck; flags.transient = True; } else if (win == client.window_group) { - //jr This doesn't look quite right... - if ((client.transient_for = openbox->searchGroup(win, this))) { + //jr This doesn't look quite right... + if ((client.transient_for = openbox.searchGroup(win, this))) { client.transient_for->client.transient = this; flags.stuck = client.transient_for->flags.stuck; flags.transient = True; @@ -2393,10 +2389,10 @@ void OpenboxWindow::propertyNotifyEvent(Atom atom) { if (client.max_width <= client.min_width && client.max_height <= client.min_height) decorations.maximize = decorations.handle = - functions.resize = functions.maximize = False; + functions.resize = functions.maximize = False; else decorations.maximize = decorations.handle = - functions.resize = functions.maximize = True; + functions.resize = functions.maximize = True; } int x = frame.x, y = frame.y; @@ -2412,12 +2408,15 @@ void OpenboxWindow::propertyNotifyEvent(Atom atom) { } default: - if (atom == openbox->getWMProtocolsAtom()) { + if (atom == openbox.getWMProtocolsAtom()) { getWMProtocols(); if (decorations.close && (! frame.close_button)) { createCloseButton(); - if (decorations.titlebar) positionButtons(True); + if (decorations.titlebar) { + positionButtons(); + decorateLabel(); + } if (windowmenu) windowmenu->reconfigure(); } } @@ -2425,7 +2424,7 @@ void OpenboxWindow::propertyNotifyEvent(Atom atom) { break; } - openbox->ungrab(); + openbox.ungrab(); } @@ -2443,7 +2442,7 @@ void OpenboxWindow::exposeEvent(XExposeEvent *ee) { void OpenboxWindow::configureRequestEvent(XConfigureRequestEvent *cr) { if (cr->window == client.window) { - openbox->grab(); + openbox.grab(); if (! validateClient()) return; int cx = frame.x, cy = frame.y; @@ -2475,37 +2474,35 @@ void OpenboxWindow::configureRequestEvent(XConfigureRequestEvent *cr) { case Above: case TopIf: default: - if (flags.iconic) deiconify(); - screen->getWorkspace(workspace_number)->raiseWindow(this); - break; + if (flags.iconic) deiconify(); + screen->getWorkspace(workspace_number)->raiseWindow(this); + break; case Below: case BottomIf: - if (flags.iconic) deiconify(); - screen->getWorkspace(workspace_number)->lowerWindow(this); - break; + if (flags.iconic) deiconify(); + screen->getWorkspace(workspace_number)->lowerWindow(this); + break; } } - openbox->ungrab(); + openbox.ungrab(); } } void OpenboxWindow::buttonPressEvent(XButtonEvent *be) { - openbox->grab(); + openbox.grab(); if (! validateClient()) return; int stack_change = 1; // < 0 means to lower the window - // > 0 means to raise the window - // 0 means to leave it where it is - + // > 0 means to raise the window + // 0 means to leave it where it is + // alt + left/right click begins interactively moving/resizing the window // when the mouse is moved if (be->state == Mod1Mask && (be->button == 1 || be->button == 3)) { - frame.grab_x = be->x_root - frame.x - frame.border_w; - frame.grab_y = be->y_root - frame.y - frame.border_w; if (be->button == 3) { if (screen->getWindowZones() == 4 && be->y < (signed) frame.height / 2) { @@ -2520,15 +2517,15 @@ void OpenboxWindow::buttonPressEvent(XButtonEvent *be) { resize_zone |= ZoneRight; } } - // control + left click on the titlebar shades the window + // control + left click on the titlebar shades the window } else if (be->state == ControlMask && be->button == 1) { if (be->window == frame.title || be->window == frame.label) shade(); - // left click + // left click } else if (be->state == 0 && be->button == 1) { if (windowmenu && windowmenu->isVisible()) - windowmenu->hide(); + windowmenu->hide(); if (be->window == frame.maximize_button) { redrawMaximizeButton(True); @@ -2542,7 +2539,7 @@ void OpenboxWindow::buttonPressEvent(XButtonEvent *be) { be->window == frame.label) { // shade the window when the titlebar is double clicked if ( (be->time - lastButtonPressTime) <= - openbox->getDoubleClickInterval()) { + openbox.getDoubleClickInterval()) { lastButtonPressTime = 0; shade(); } else { @@ -2565,22 +2562,22 @@ void OpenboxWindow::buttonPressEvent(XButtonEvent *be) { else if (be->window == frame.right_grip) resize_zone = ZoneBottom | ZoneRight; } - // middle click + // middle click } else if (be->state == 0 && be->button == 2) { if (be->window == frame.maximize_button) { redrawMaximizeButton(True); - // a middle click anywhere on the window's frame except for on the buttons - // will lower the window + // a middle click anywhere on the window's frame except for on the buttons + // will lower the window } else if (! (be->window == frame.iconify_button || be->window == frame.close_button) ) { stack_change = -1; } - // right click + // right click } else if (be->state == 0 && be->button == 3) { if (be->window == frame.maximize_button) { redrawMaximizeButton(True); - // a right click on the window's frame will show or hide the window's - // windowmenu + // a right click on the window's frame will show or hide the window's + // windowmenu } else if (be->window == frame.title || be->window == frame.label || be->window == frame.handle || @@ -2594,7 +2591,7 @@ void OpenboxWindow::buttonPressEvent(XButtonEvent *be) { mx = be->x_root - windowmenu->getWidth() / 2; if (be->window == frame.title || be->window == frame.label) { my = frame.y + frame.title_h; - } else if (be->window = frame.handle) { + } else if (be->window == frame.handle) { my = frame.y + frame.y_handle - windowmenu->getHeight(); } else { // (be->window == frame.window) if (be->y <= (signed) frame.bevel_w) { @@ -2605,17 +2602,17 @@ void OpenboxWindow::buttonPressEvent(XButtonEvent *be) { } if (mx > (signed) (frame.x + frame.width - - windowmenu->getWidth())) { + windowmenu->getWidth())) { mx = frame.x + frame.width - windowmenu->getWidth(); } else if (mx < frame.x) { mx = frame.x; } if (my > (signed) (frame.y + frame.y_handle - - windowmenu->getHeight())) { + windowmenu->getHeight())) { my = frame.y + frame.y_handle - windowmenu->getHeight(); } else if (my < (signed) (frame.y + - ((decorations.titlebar) ? frame.title_h : frame.y_border))) { + ((decorations.titlebar) ? frame.title_h : frame.y_border))) { my = frame.y + ((decorations.titlebar) ? frame.title_h : frame.y_border); } @@ -2628,21 +2625,21 @@ void OpenboxWindow::buttonPressEvent(XButtonEvent *be) { } } } - // mouse wheel up + // mouse wheel up } else if (be->state == 0 && be->button == 4) { if ((be->window == frame.label || - be->window == frame.title) && + be->window == frame.title) && !flags.shaded) shade(); - // mouse wheel down + // mouse wheel down } else if (be->state == 0 && be->button == 5) { if ((be->window == frame.label || - be->window == frame.title) && + be->window == frame.title) && flags.shaded) shade(); } - if (! (flags.focused || screen->isSloppyFocus()) ) { + if (! (flags.focused || screen->sloppyFocus()) ) { setInputFocus(); // any click focus' the window in 'click to focus' } if (stack_change < 0) { @@ -2650,13 +2647,13 @@ void OpenboxWindow::buttonPressEvent(XButtonEvent *be) { } else if (stack_change > 0) { screen->getWorkspace(workspace_number)->raiseWindow(this); } - - openbox->ungrab(); + + openbox.ungrab(); } void OpenboxWindow::buttonReleaseEvent(XButtonEvent *re) { - openbox->grab(); + openbox.grab(); if (! validateClient()) return; @@ -2665,7 +2662,7 @@ void OpenboxWindow::buttonReleaseEvent(XButtonEvent *re) { if (re->window == frame.window) { XUngrabPointer(display, CurrentTime); // why? i dont know } - // left button released + // left button released } else if (re->button == 1) { if (re->window == frame.maximize_button) { if (re->state == Button1Mask && // only the left button was depressed @@ -2687,13 +2684,13 @@ void OpenboxWindow::buttonReleaseEvent(XButtonEvent *re) { if (re->state == Button1Mask && // only the left button was depressed (re->x >= 0) && ((unsigned) re->x <= frame.button_w) && (re->y >= 0) && ((unsigned) re->y <= frame.button_h)) { - close(); + close(); } //we should always redraw the close button. some applications //eg. acroread don't honour the close. redrawCloseButton(False); } - // middle button released + // middle button released } else if (re->button == 2) { if (re->window == frame.maximize_button) { if (re->state == Button2Mask && // only the middle button was depressed @@ -2704,7 +2701,7 @@ void OpenboxWindow::buttonReleaseEvent(XButtonEvent *re) { redrawMaximizeButton(False); } } - // right button released + // right button released } else if (re->button == 3) { if (re->window == frame.maximize_button) { if (re->state == Button3Mask && // only the right button was depressed @@ -2716,27 +2713,13 @@ void OpenboxWindow::buttonReleaseEvent(XButtonEvent *re) { } } } - + // when the window is being interactively moved, a button release stops the // move where it is if (flags.moving) { - flags.moving = False; - - openbox->maskWindowEvents(0, (OpenboxWindow *) 0); - if (!screen->doOpaqueMove()) { - XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(), - frame.move_x, frame.move_y, frame.resize_w - 1, - frame.resize_h - 1); - - configure(frame.move_x, frame.move_y, frame.width, frame.height); - openbox->ungrab(); - } else { - configure(frame.x, frame.y, frame.width, frame.height); - } - screen->hideGeometry(); - XUngrabPointer(display, CurrentTime); - // when the window is being interactively resized, a button release stops the - // resizing + endMove(); + // when the window is being interactively resized, a button release stops the + // resizing } else if (flags.resizing) { flags.resizing = False; XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(), @@ -2746,142 +2729,189 @@ void OpenboxWindow::buttonReleaseEvent(XButtonEvent *re) { if (resize_zone & ZoneLeft) { left_fixsize(); } else { // when resizing with "Alt+Button3", the resize is the same as if - // done with the right grip (the right side of the window is what - // moves) + // done with the right grip (the right side of the window is what + // moves) right_fixsize(); } // unset maximized state when resized after fully maximized if (flags.maximized == 1) { - maximize(0); + maximize(0); } configure(frame.resize_x, frame.resize_y, frame.resize_w - (frame.border_w * 2), frame.resize_h - (frame.border_w * 2)); - openbox->ungrab(); + openbox.ungrab(); XUngrabPointer(display, CurrentTime); resize_zone = 0; } - openbox->ungrab(); + openbox.ungrab(); } -void OpenboxWindow::motionNotifyEvent(XMotionEvent *me) { - if (!flags.resizing && (me->state & Button1Mask) && functions.move && - (frame.title == me->window || frame.label == me->window || - frame.handle == me->window || frame.window == me->window)) { - if (! flags.moving) { - XGrabPointer(display, me->window, False, Button1MotionMask | - ButtonReleaseMask, GrabModeAsync, GrabModeAsync, - None, openbox->getMoveCursor(), CurrentTime); +void OpenboxWindow::startMove(int x, int y) { + ASSERT(!flags.moving); - if (windowmenu && windowmenu->isVisible()) - windowmenu->hide(); + // make sure only one window is moving at a time + OpenboxWindow *w = openbox.getMaskedWindow(); + if (w != (OpenboxWindow *) 0 && w->flags.moving) + w->endMove(); - flags.moving = True; + XGrabPointer(display, frame.window, False, PointerMotionMask | + ButtonReleaseMask, GrabModeAsync, GrabModeAsync, + None, openbox.getMoveCursor(), CurrentTime); - openbox->maskWindowEvents(client.window, this); + if (windowmenu && windowmenu->isVisible()) + windowmenu->hide(); - if (! screen->doOpaqueMove()) { - openbox->grab(); + flags.moving = True; - frame.move_x = frame.x; - frame.move_y = frame.y; - frame.resize_w = frame.width + (frame.border_w * 2); - frame.resize_h = ((flags.shaded) ? frame.title_h : frame.height) + - (frame.border_w * 2); + openbox.maskWindowEvents(client.window, this); - screen->showPosition(frame.x, frame.y); + if (! screen->opaqueMove()) { + openbox.grab(); - XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(), - frame.move_x, frame.move_y, - frame.resize_w - 1, frame.resize_h - 1); - } - } else { - int dx = me->x_root - frame.grab_x, dy = me->y_root - frame.grab_y; - - dx -= frame.border_w; - dy -= frame.border_w; - - int snap_distance = screen->getEdgeSnapThreshold(); - if (snap_distance) { - int drx = screen->getWidth() - (dx + frame.snap_w); - - if (dx < drx && (dx > 0 && dx < snap_distance) || - (dx < 0 && dx > -snap_distance) ) - dx = 0; - else if ( (drx > 0 && drx < snap_distance) || - (drx < 0 && drx > -snap_distance) ) - dx = screen->getWidth() - frame.snap_w; - - int dtty, dbby, dty, dby; - switch (screen->getToolbarPlacement()) { - case Toolbar::TopLeft: - case Toolbar::TopCenter: - case Toolbar::TopRight: - dtty = screen->getToolbar()->getExposedHeight() + - frame.border_w; - dbby = screen->getHeight(); - break; - - default: - dtty = 0; - dbby = screen->getToolbar()->getY(); - break; - } + frame.move_x = frame.x; + frame.move_y = frame.y; + frame.resize_w = frame.width + (frame.border_w * 2); + frame.resize_h = ((flags.shaded) ? frame.title_h : frame.height) + + (frame.border_w * 2); - dty = dy - dtty; - dby = dbby - (dy + frame.snap_h); + screen->showPosition(frame.x, frame.y); - if ( (dy > 0 && dty < snap_distance) || - (dy < 0 && dty > -snap_distance) ) - dy = dtty; - else if ( (dby > 0 && dby < snap_distance) || - (dby < 0 && dby > -snap_distance) ) - dy = dbby - frame.snap_h; - } + XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(), + frame.move_x, frame.move_y, + frame.resize_w - 1, frame.resize_h - 1); + } + frame.grab_x = x - frame.x - frame.border_w; + frame.grab_y = y - frame.y - frame.border_w; +} - if (screen->doOpaqueMove()) { - configure(dx, dy, frame.width, frame.height); - } else { - XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(), - frame.move_x, frame.move_y, frame.resize_w - 1, - frame.resize_h - 1); - frame.move_x = dx; - frame.move_y = dy; +void OpenboxWindow::doMove(int x, int y) { + ASSERT(flags.moving); - XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(), - frame.move_x, frame.move_y, frame.resize_w - 1, - frame.resize_h - 1); - } + int dx = x - frame.grab_x, dy = y - frame.grab_y; + + dx -= frame.border_w; + dy -= frame.border_w; + + int snap_distance = screen->edgeSnapThreshold(); + // width/height of the snapping window + unsigned int snap_w = frame.width + (frame.border_w * 2); + unsigned int snap_h = area().h() + (frame.border_w * 2); + if (snap_distance) { + int drx = screen->size().w() - (dx + snap_w); + + if (dx < drx && (dx > 0 && dx < snap_distance) || + (dx < 0 && dx > -snap_distance) ) + dx = 0; + else if ( (drx > 0 && drx < snap_distance) || + (drx < 0 && drx > -snap_distance) ) + dx = screen->size().w() - snap_w; + + int dtty, dbby, dty, dby; + switch (screen->getToolbar()->placement()) { + case Toolbar::TopLeft: + case Toolbar::TopCenter: + case Toolbar::TopRight: + dtty = screen->getToolbar()->getExposedHeight() + + frame.border_w; + dbby = screen->size().h(); + break; - screen->showPosition(dx, dy); + default: + dtty = 0; + dbby = screen->getToolbar()->area().y(); + break; } - } else if (functions.resize && - (((me->state & Button1Mask) && (me->window == frame.right_grip || - me->window == frame.left_grip)) || - (me->state & (Mod1Mask | Button3Mask) && - me->window == frame.window))) { + + dty = dy - dtty; + dby = dbby - (dy + snap_h); + + if ( (dy > 0 && dty < snap_distance) || + (dy < 0 && dty > -snap_distance) ) + dy = dtty; + else if ( (dby > 0 && dby < snap_distance) || + (dby < 0 && dby > -snap_distance) ) + dy = dbby - snap_h; + } + + if (screen->opaqueMove()) { + configure(dx, dy, frame.width, frame.height); + } else { + XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(), + frame.move_x, frame.move_y, frame.resize_w - 1, + frame.resize_h - 1); + + frame.move_x = dx; + frame.move_y = dy; + + XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(), + frame.move_x, frame.move_y, frame.resize_w - 1, + frame.resize_h - 1); + } + + screen->showPosition(dx, dy); +} + + +void OpenboxWindow::endMove() { + ASSERT(flags.moving); + + flags.moving = False; + + openbox.maskWindowEvents(0, (OpenboxWindow *) 0); + if (!screen->opaqueMove()) { + XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(), + frame.move_x, frame.move_y, frame.resize_w - 1, + frame.resize_h - 1); + + configure(frame.move_x, frame.move_y, frame.width, frame.height); + openbox.ungrab(); + } else { + configure(frame.x, frame.y, frame.width, frame.height); + } + screen->hideGeometry(); + XUngrabPointer(display, CurrentTime); + // if there are any left over motions from the move, drop them now cuz they + // cause problems + XEvent e; + while (XCheckTypedWindowEvent(display, frame.window, MotionNotify, &e)); +} + + +void OpenboxWindow::motionNotifyEvent(XMotionEvent *me) { + if (flags.moving) + doMove(me->x_root, me->y_root); + else if (!flags.resizing && (me->state & Button1Mask) && functions.move && + (frame.title == me->window || frame.label == me->window || + frame.handle == me->window || frame.window == me->window)) + startMove(me->x_root, me->y_root); + else if (functions.resize && + (((me->state & Button1Mask) && (me->window == frame.right_grip || + me->window == frame.left_grip)) || + (me->state == (Mod1Mask | Button3Mask) && + me->window == frame.window))) { Bool left = resize_zone & ZoneLeft; if (! flags.resizing) { Cursor cursor; if (resize_zone & ZoneTop) cursor = (resize_zone & ZoneLeft) ? - openbox->getUpperLeftAngleCursor() : - openbox->getUpperRightAngleCursor(); + openbox.getUpperLeftAngleCursor() : + openbox.getUpperRightAngleCursor(); else cursor = (resize_zone & ZoneLeft) ? - openbox->getLowerLeftAngleCursor() : - openbox->getLowerRightAngleCursor(); + openbox.getLowerLeftAngleCursor() : + openbox.getLowerRightAngleCursor(); XGrabPointer(display, me->window, False, ButtonMotionMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime); flags.resizing = True; - openbox->grab(); + openbox.grab(); int gx, gy; if (resize_zone & ZoneRight) @@ -2900,17 +2930,17 @@ void OpenboxWindow::motionNotifyEvent(XMotionEvent *me) { if (left) left_fixsize(&gx, &gy); else - right_fixsize(&gx, &gy); + right_fixsize(&gx, &gy); screen->showGeometry(gx, gy); XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(), - frame.resize_x, frame.resize_y, - frame.resize_w - 1, frame.resize_h - 1); + frame.resize_x, frame.resize_y, + frame.resize_w - 1, frame.resize_h - 1); } else { XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(), - frame.resize_x, frame.resize_y, - frame.resize_w - 1, frame.resize_h - 1); + frame.resize_x, frame.resize_y, + frame.resize_w - 1, frame.resize_h - 1); int gx, gy; @@ -2927,15 +2957,15 @@ void OpenboxWindow::motionNotifyEvent(XMotionEvent *me) { left_fixsize(&gx, &gy); } else { - frame.resize_w = frame.width + (me->x - frame.grab_x); - if (frame.resize_w < 1) frame.resize_w = 1; + frame.resize_w = frame.width + (me->x - frame.grab_x); + if (frame.resize_w < 1) frame.resize_w = 1; - right_fixsize(&gx, &gy); + right_fixsize(&gx, &gy); } XDrawRectangle(display, screen->getRootWindow(), screen->getOpGC(), - frame.resize_x, frame.resize_y, - frame.resize_w - 1, frame.resize_h - 1); + frame.resize_x, frame.resize_y, + frame.resize_w - 1, frame.resize_h - 1); screen->showGeometry(gx, gy); } @@ -2945,14 +2975,14 @@ void OpenboxWindow::motionNotifyEvent(XMotionEvent *me) { #ifdef SHAPE void OpenboxWindow::shapeEvent(XShapeEvent *) { - if (openbox->hasShapeExtensions()) { + if (openbox.hasShapeExtensions()) { if (flags.shaped) { - openbox->grab(); + openbox.grab(); if (! validateClient()) return; XShapeCombineShape(display, frame.window, ShapeBounding, - frame.mwm_border_w, frame.y_border + - frame.mwm_border_w, client.window, - ShapeBounding, ShapeSet); + frame.mwm_border_w, frame.y_border + + frame.mwm_border_w, client.window, + ShapeBounding, ShapeSet); int num = 1; XRectangle xrect[2]; @@ -2961,35 +2991,35 @@ void OpenboxWindow::shapeEvent(XShapeEvent *) { xrect[0].height = frame.y_border; if (decorations.handle) { - xrect[1].x = 0; - xrect[1].y = frame.y_handle; - xrect[1].width = frame.width; - xrect[1].height = frame.handle_h + frame.border_w; - num++; + xrect[1].x = 0; + xrect[1].y = frame.y_handle; + xrect[1].width = frame.width; + xrect[1].height = frame.handle_h + frame.border_w; + num++; } XShapeCombineRectangles(display, frame.window, ShapeBounding, 0, 0, - xrect, num, ShapeUnion, Unsorted); - openbox->ungrab(); + xrect, num, ShapeUnion, Unsorted); + openbox.ungrab(); } } } #endif // SHAPE -Bool OpenboxWindow::validateClient(void) { +bool OpenboxWindow::validateClient(void) { XSync(display, False); XEvent e; if (XCheckTypedWindowEvent(display, client.window, DestroyNotify, &e) || XCheckTypedWindowEvent(display, client.window, UnmapNotify, &e)) { XPutBackEvent(display, &e); - openbox->ungrab(); + openbox.ungrab(); - return False; + return false; } - return True; + return true; } @@ -3008,6 +3038,8 @@ void OpenboxWindow::restore(void) { XMapWindow(display, client.window); XFlush(display); + + delete this; } @@ -3059,27 +3091,31 @@ void OpenboxWindow::changeOpenboxHints(OpenboxHints *net) { switch (net->decoration) { case DecorNone: decorations.titlebar = decorations.border = decorations.handle = - decorations.iconify = decorations.maximize = decorations.menu = False; + decorations.iconify = decorations.maximize = decorations.menu = False; break; default: case DecorNormal: - decorations.titlebar = decorations.border = decorations.handle = - decorations.iconify = decorations.maximize = decorations.menu = True; + decorations.titlebar = decorations.iconify = decorations.menu = + decorations.border = True; + decorations.handle = (functions.resize && !flags.transient); + decorations.maximize = functions.maximize; break; case DecorTiny: decorations.titlebar = decorations.iconify = decorations.menu = True; - decorations.border = decorations.handle = decorations.maximize = False; - + decorations.border = decorations.border = decorations.handle = False; + decorations.maximize = functions.maximize; + break; case DecorTool: - decorations.titlebar = decorations.menu = functions.move = True; - decorations.iconify = decorations.border = decorations.handle = - decorations.maximize = False; + decorations.titlebar = decorations.menu = True; + decorations.iconify = decorations.border = False; + decorations.handle = (functions.resize && !flags.transient); + decorations.maximize = functions.maximize; break; } @@ -3117,12 +3153,12 @@ void OpenboxWindow::upsize(void) { // the height of the titlebar is based upon the height of the font being // used to display the window's title WindowStyle *style = screen->getWindowStyle(); - if (i18n->multibyte()) + if (i18n.multibyte()) frame.title_h = (style->fontset_extents->max_ink_extent.height + - (frame.bevel_w * 2) + 2); + (frame.bevel_w * 2) + 2); else frame.title_h = (style->font->ascent + style->font->descent + - (frame.bevel_w * 2) + 2); + (frame.bevel_w * 2) + 2); frame.label_h = frame.title_h - (frame.bevel_w * 2); frame.button_w = frame.button_h = (frame.label_h - 2); @@ -3145,12 +3181,9 @@ void OpenboxWindow::upsize(void) { frame.handle_h = 0; frame.grip_w = frame.grip_h = 0; } - + frame.width = client.width + (frame.mwm_border_w * 2); frame.height = frame.y_handle + frame.handle_h; - - frame.snap_w = frame.width + (frame.border_w * 2); - frame.snap_h = frame.height + (frame.border_w * 2); } @@ -3172,18 +3205,15 @@ void OpenboxWindow::downsize(void) { - frame.handle_h - (decorations.handle ? frame.border_w : 0); frame.y_handle = frame.border_h + frame.y_border + frame.border_w; - - frame.snap_w = frame.width + (frame.border_w * 2); - frame.snap_h = frame.height + (frame.border_w * 2); } void OpenboxWindow::right_fixsize(int *gx, int *gy) { // calculate the size of the client window and conform it to the // size specified by the size hints of the client window... - int dx = frame.resize_w - client.base_width - (frame.mwm_border_w * 2) - + int dx = 1 + frame.resize_w - client.base_width - (frame.mwm_border_w * 2) - (frame.border_w * 2) + (client.width_inc / 2); - int dy = frame.resize_h - frame.y_border - client.base_height - + int dy = 1 + frame.resize_h - frame.y_border - client.base_height - frame.handle_h - (frame.border_w * 3) - (frame.mwm_border_w * 2) + (client.height_inc / 2); @@ -3201,9 +3231,9 @@ void OpenboxWindow::right_fixsize(int *gx, int *gy) { dx = (dx * client.width_inc) + client.base_width; dy = (dy * client.height_inc) + client.base_height; - frame.resize_w = dx + (frame.mwm_border_w * 2) + (frame.border_w * 2); + frame.resize_w = dx + (frame.mwm_border_w * 2) + (frame.border_w * 2) - 1; frame.resize_h = dy + frame.y_border + frame.handle_h + - (frame.mwm_border_w * 2) + (frame.border_w * 3); + (frame.mwm_border_w * 2) + (frame.border_w * 3) - 1; if (resize_zone & ZoneTop) frame.resize_y = frame.y + frame.height - frame.resize_h + screen->getBorderWidth() * 2; @@ -3213,9 +3243,9 @@ void OpenboxWindow::right_fixsize(int *gx, int *gy) { void OpenboxWindow::left_fixsize(int *gx, int *gy) { // calculate the size of the client window and conform it to the // size specified by the size hints of the client window... - int dx = frame.x + frame.width - frame.resize_x - client.base_width - + int dx = 1 + frame.x + frame.width - frame.resize_x - client.base_width - (frame.mwm_border_w * 2) + (client.width_inc / 2); - int dy = frame.resize_h - frame.y_border - client.base_height - + int dy = 1 + frame.resize_h - frame.y_border - client.base_height - frame.handle_h - (frame.border_w * 3) - (frame.mwm_border_w * 2) + (client.height_inc / 2); @@ -3233,13 +3263,13 @@ void OpenboxWindow::left_fixsize(int *gx, int *gy) { dx = (dx * client.width_inc) + client.base_width; dy = (dy * client.height_inc) + client.base_height; - frame.resize_w = dx + (frame.mwm_border_w * 2) + (frame.border_w * 2); + frame.resize_w = dx + (frame.mwm_border_w * 2) + (frame.border_w * 2) - 1; frame.resize_x = frame.x + frame.width - frame.resize_w + - (frame.border_w * 2); + (frame.border_w * 2); frame.resize_h = dy + frame.y_border + frame.handle_h + - (frame.mwm_border_w * 2) + (frame.border_w * 3); + (frame.mwm_border_w * 2) + (frame.border_w * 3) - 1; if (resize_zone & ZoneTop) frame.resize_y = frame.y + frame.height - frame.resize_h + screen->getBorderWidth() * 2; - + }