From: Dana Jansens Date: Mon, 10 Feb 2003 07:16:56 +0000 (+0000) Subject: stop using a desktop number for iconic windows. woot! X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=4ef15148365c223b8e810611a10dc27dc5fba355;p=chaz%2Fopenbox stop using a desktop number for iconic windows. woot! --- diff --git a/scripts/focus.py b/scripts/focus.py index e9a974b5..2fb6188a 100644 --- a/scripts/focus.py +++ b/scripts/focus.py @@ -29,6 +29,7 @@ _disable = 0 def _focusable(client, desktop): if not client.normal(): return 0 if not (client.canFocus() or client.focusNotify()): return 0 + if client.iconic(): return 0 if AVOID_SKIP_TASKBAR and client.skipTaskbar(): return 0 desk = client.desktop() diff --git a/src/client.cc b/src/client.cc index b495a71c..787be429 100644 --- a/src/client.cc +++ b/src/client.cc @@ -45,7 +45,7 @@ Client::Client(int screen, Window window) _positioned = false; _disabled_decorations = 0; _group = None; - _desktop = _old_desktop = 0; + _desktop = 0; getArea(); getDesktop(); @@ -730,62 +730,46 @@ void Client::setWMState(long state) switch (state) { case IconicState: - setDesktop(ICONIC_DESKTOP); + iconify(true); break; case NormalState: - setDesktop(openbox->screen(_screen)->desktop()); + iconify(false); break; } } -void Client::setDesktop(long target) +void Client::setDesktop(unsigned int target) { if (target == _desktop) return; - printf("Setting desktop %ld\n", target); + printf("Setting desktop %u\n", target); - if (!(target >= 0 || target == (signed)0xffffffff || - target == ICONIC_DESKTOP)) + if (!(target < openbox->screen(_screen)->numDesktops() || + target == 0xffffffff)) return; - _old_desktop = _desktop; _desktop = target; - // set the desktop hint, but not if we're iconifying - if (_desktop != ICONIC_DESKTOP) - otk::Property::set(_window, otk::Property::atoms.net_wm_desktop, - otk::Property::atoms.cardinal, (unsigned)_desktop); + // set the desktop hint + otk::Property::set(_window, otk::Property::atoms.net_wm_desktop, + otk::Property::atoms.cardinal, _desktop); // 'move' the window to the new desktop - if (_desktop == openbox->screen(_screen)->desktop() || - _desktop == (signed)0xffffffff) + showhide(); + + openbox->screen(_screen)->updateStruts(); +} + + +void Client::showhide() +{ + if (!_iconic && + (_desktop == openbox->screen(_screen)->desktop() || + _desktop == 0xffffffff)) frame->show(); else frame->hide(); - - // Handle Iconic state. Iconic state is maintained by the client being a - // member of the ICONIC_DESKTOP, so this is where we make iconifying and - // uniconifying happen. - bool i = _desktop == ICONIC_DESKTOP; - if (i != _iconic) { // has the state changed? - _iconic = i; - if (_iconic) { - _wmstate = IconicState; - ignore_unmaps++; - // we unmap the client itself so that we can get MapRequest events, and - // because the ICCCM tells us to! - XUnmapWindow(**otk::display, _window); - } else { - _wmstate = NormalState; - XMapWindow(**otk::display, _window); - } - changeState(); - } - - changeAllowedActions(); - frame->adjustState(); - openbox->screen(_screen)->updateStruts(); } @@ -1029,14 +1013,14 @@ void Client::clientMessageHandler(const XClientMessageEvent &e) printf("net_active_window for 0x%lx\n", _window); #endif if (_iconic) - setDesktop(openbox->screen(_screen)->desktop()); + iconify(false); if (_shaded) shade(false); focus(); openbox->screen(_screen)->raiseWindow(this); } else if (e.message_type == otk::Property::atoms.openbox_active_window) { if (_iconic) - setDesktop(openbox->screen(_screen)->desktop()); + iconify(false); if (e.data.l[0] && _shaded) shade(false); focus(); @@ -1325,7 +1309,7 @@ void Client::applyStartupState() if (_iconic) { _iconic = false; - setDesktop(ICONIC_DESKTOP); + iconify(true); } if (_fullscreen) { _fullscreen = false; @@ -1395,8 +1379,7 @@ void Client::maximize(bool max, int dir, bool savearea) if (dir == 2 && !_max_vert) return; } - const otk::Rect &a = openbox->screen(_screen)->area(_iconic ? - _old_desktop : _desktop); + const otk::Rect &a = openbox->screen(_screen)->area(_desktop); int x = frame->area().x(), y = frame->area().y(), w = _area.width(), h = _area.height(); @@ -1541,9 +1524,7 @@ void Client::fullscreen(bool fs, bool savearea) delete dimensions; } else { // pick some fallbacks... - const otk::Rect &a = openbox->screen(_screen)->area(_iconic ? - _old_desktop : - _desktop); + const otk::Rect &a = openbox->screen(_screen)->area(_desktop); x = a.x() + a.width() / 4; y = a.y() + a.height() / 4; w = a.width() / 2; @@ -1564,6 +1545,32 @@ void Client::fullscreen(bool fs, bool savearea) } +void Client::iconify(bool iconic, bool curdesk) +{ + if (_iconic == iconic) return; // nothing to do + + _iconic = iconic; + + if (_iconic) { + _wmstate = IconicState; + ignore_unmaps++; + // we unmap the client itself so that we can get MapRequest events, and + // because the ICCCM tells us to! + XUnmapWindow(**otk::display, _window); + } else { + if (curdesk) + setDesktop(openbox->screen(_screen)->desktop()); + _wmstate = NormalState; + XMapWindow(**otk::display, _window); + } + changeState(); + + showhide(); + + openbox->screen(_screen)->updateStruts(); +} + + void Client::disableDecorations(DecorationFlags flags) { _disabled_decorations = flags; @@ -1856,7 +1863,7 @@ void Client::mapRequestHandler(const XMapRequestEvent &e) assert(_iconic); // we shouldn't be able to get this unless we're iconic // move to the current desktop (uniconify) - setDesktop(openbox->screen(_screen)->desktop()); + iconify(false); // XXX: should we focus/raise the window? (basically a net_wm_active_window) } diff --git a/src/client.hh b/src/client.hh index 0505c361..ff119faf 100644 --- a/src/client.hh +++ b/src/client.hh @@ -164,10 +164,6 @@ public: static const long no_propagate_mask = ButtonPressMask | ButtonReleaseMask | ButtonMotionMask; - //! The desktop value which indicated the window is iconified and not on any - //! desktop - static const long ICONIC_DESKTOP = 0xfffffffe; - //! The number of unmap events to ignore on the window int ignore_unmaps; @@ -188,11 +184,7 @@ private: Client::List _transients; //! The desktop on which the window resides (0xffffffff for all desktops) - long _desktop; - - //! The last desktop to which the window belonged, mostly useful when the - //! window is iconified, to see where it used to be. - long _old_desktop; + unsigned int _desktop; //! Normal window title otk::ustring _title; @@ -380,11 +372,7 @@ private: void setState(StateAction action, long data1, long data2); //! Sends the window to the specified desktop - /*! - A window is iconified by sending it to the ICONIC_DESKTOP, and restored - by sending it to any other valid desktop. - */ - void setDesktop(long desktop); + void setDesktop(unsigned int desktop); //! Calculates the stacking layer for the client window void calcLayer(); @@ -446,6 +434,16 @@ private: */ void fullscreen(bool fs, bool savearea = true); + //! Iconifies or uniconifies the client window + /*! + @param iconic true if the window should be iconified; false if it should be + restored. + @param curdesk If iconic is false, then this determines if the window will + be uniconified to the current viewable desktop (true) or to + its previous desktop (false) + */ + void iconify(bool iconic, bool curdesk = true); + //! Maximize or unmaximize the client window /*! @param max true if the window should be maximized; false if it should be @@ -532,7 +530,7 @@ BB @param window The window id that the Client class should handle This value is a 0-based index.
A value of 0xffffffff indicates that the window exists on all desktops. */ - inline long desktop() const { return _desktop; } + inline unsigned int desktop() const { return _desktop; } //! Returns the window's title inline const otk::ustring &title() const { return _title; } //! Returns the window's title when it is iconified @@ -653,6 +651,12 @@ BB @param window The window id that the Client class should handle surroundings (struts, etc). */ void remaximize(); + + //! Shows the window if it should be shown, or hides it + /*! + Used when changing desktops, the window's state, etc. + */ + void showhide(); //! Choose a mask of decorations to not display on the client /*! diff --git a/src/screen.cc b/src/screen.cc index 081b68d1..a2514276 100644 --- a/src/screen.cc +++ b/src/screen.cc @@ -105,7 +105,7 @@ Screen::Screen(int screen) _desktop = 0; - if (!python_get_long("NUMBER_OF_DESKTOPS", &_num_desktops)) + if (!python_get_long("NUMBER_OF_DESKTOPS", (long*)&_num_desktops)) _num_desktops = 1; changeNumDesktops(_num_desktops); // set the hint @@ -217,16 +217,16 @@ void Screen::updateStruts() ClientList::const_iterator it, end = clients.end(); for (it = clients.begin(); it != end; ++it) { - long desk = (*it)->desktop(); + if ((*it)->iconic()) continue; // these dont count in the strut + + unsigned int desk = (*it)->desktop(); const otk::Strut &s = (*it)->strut(); - if (desk == (signed) 0xffffffff) + if (desk == 0xffffffff) for (unsigned int i = 0, e = _struts.size(); i < e; ++i) apply(_struts[i], s); - else if ((unsigned)desk < _struts.size()) + else if (desk < _struts.size()) apply(_struts[desk], s); - else if (desk == Client::ICONIC_DESKTOP) - continue; // skip for the 'all desktops' strut else assert(false); // invalid desktop otherwise.. // apply to the 'all desktops' strut @@ -239,7 +239,7 @@ void Screen::updateStruts() void Screen::changeWorkArea() { unsigned long *dims = new unsigned long[4 * _num_desktops]; - for (long i = 0; i < _num_desktops + 1; ++i) { + for (unsigned int i = 0; i < _num_desktops + 1; ++i) { otk::Rect old_area = _area[i]; /* #ifdef XINERAMA @@ -286,7 +286,7 @@ void Screen::changeWorkArea() (*it)->remaximize(); } else { // the 'all desktops' size - if ((*it)->desktop() == (signed) 0xffffffff) + if ((*it)->desktop() == 0xffffffff) (*it)->remaximize(); } } @@ -537,11 +537,7 @@ void Screen::manageWindow(Window window) EventData ddata(_number, client, EventAction::DisplayingWindow, 0); openbox->bindings()->fireEvent(&ddata); - // if on the current desktop.. (or all desktops) - if (client->desktop() == _desktop || - client->desktop() == (signed)0xffffffff) { - client->frame->show(); - } + client->showhide(); client->applyStartupState(); @@ -708,13 +704,13 @@ void Screen::raiseWindow(Client *client) changeStackingList(); } -void Screen::changeDesktop(long desktop) +void Screen::changeDesktop(unsigned int desktop) { - if (!(desktop >= 0 && desktop < _num_desktops)) return; + if (desktop >= _num_desktops) return; - printf("Moving to desktop %ld\n", desktop); + printf("Moving to desktop %u\n", desktop); - long old = _desktop; + unsigned int old = _desktop; _desktop = desktop; otk::Property::set(_info->rootWindow(), @@ -724,20 +720,15 @@ void Screen::changeDesktop(long desktop) if (old == _desktop) return; ClientList::iterator it, end = clients.end(); - for (it = clients.begin(); it != end; ++it) { - if ((*it)->desktop() == old) { - (*it)->frame->hide(); - } else if ((*it)->desktop() == _desktop) { - (*it)->frame->show(); - } - } + for (it = clients.begin(); it != end; ++it) + (*it)->showhide(); // force the callbacks to fire if (!openbox->focusedClient()) openbox->setFocusedClient(0); } -void Screen::changeNumDesktops(long num) +void Screen::changeNumDesktops(unsigned int num) { assert(num > 0); @@ -746,9 +737,8 @@ void Screen::changeNumDesktops(long num) // move windows on desktops that will no longer exist! ClientList::iterator it, end = clients.end(); for (it = clients.begin(); it != end; ++it) { - int d = (*it)->desktop(); - if (d >= num && !(d == (signed) 0xffffffff || - d == Client::ICONIC_DESKTOP)) { + unsigned int d = (*it)->desktop(); + if (d >= num && d != 0xffffffff) { XEvent ce; ce.xclient.type = ClientMessage; ce.xclient.message_type = otk::Property::atoms.net_wm_desktop; @@ -794,15 +784,13 @@ void Screen::updateDesktopNames() otk::Property::atoms.net_desktop_names, otk::Property::utf8, &num, &_desktop_names)) _desktop_names.clear(); - while ((long)_desktop_names.size() < _num_desktops) + while (_desktop_names.size() < _num_desktops) _desktop_names.push_back("Unnamed"); } -void Screen::setDesktopName(long i, const otk::ustring &name) +void Screen::setDesktopName(unsigned int i, const otk::ustring &name) { - assert(i >= 0); - if (i >= _num_desktops) return; otk::Property::StringVect newnames = _desktop_names; @@ -813,10 +801,9 @@ void Screen::setDesktopName(long i, const otk::ustring &name) } -const otk::Rect& Screen::area(long desktop) const { - assert(desktop >= 0 || desktop == (signed) 0xffffffff); - assert(desktop < _num_desktops || desktop == (signed) 0xffffffff); - if (desktop >= 0 && desktop < _num_desktops) +const otk::Rect& Screen::area(unsigned int desktop) const { + assert(desktop < _num_desktops || desktop == 0xffffffff); + if (desktop < _num_desktops) return _area[desktop]; else return _area[_num_desktops]; diff --git a/src/screen.hh b/src/screen.hh index 16a4225b..9b3618c9 100644 --- a/src/screen.hh +++ b/src/screen.hh @@ -80,10 +80,10 @@ private: ClientList _stacking; //! The desktop currently being displayed - long _desktop; + unsigned int _desktop; //! The number of desktops - long _num_desktops; + unsigned int _num_desktops; //! The names of all desktops otk::Property::StringVect _desktop_names; @@ -118,14 +118,14 @@ private: @param desktop The number of the desktop to switch to (starts from 0). If the desktop is out of valid range, it is ignored. */ - void changeDesktop(long desktop); + void changeDesktop(unsigned int desktop); //! Changes the number of desktops. /*! @param num The number of desktops that should exist. This value must be greater than 0 or it will be ignored. */ - void changeNumDesktops(long num); + void changeNumDesktops(unsigned int num); public: #ifndef SWIG @@ -146,9 +146,9 @@ public: //! An offscreen window which gets focus when nothing else has it inline Window focuswindow() const { return _focuswindow; } //! Returns the desktop being displayed - inline long desktop() const { return _desktop; } + inline unsigned int desktop() const { return _desktop; } //! Returns the number of desktops - inline long numDesktops() const { return _num_desktops; } + inline unsigned int numDesktops() const { return _num_desktops; } //! Returns the area of the screen not reserved by applications' Struts /*! @@ -156,7 +156,7 @@ public: 0xffffffff will return an area that combines all struts on all desktops. */ - const otk::Rect& area(long desktop) const; + const otk::Rect& area(unsigned int desktop) const; //! Update's the screen's combined strut of all the clients. /*! @@ -198,7 +198,7 @@ public: @param name The name to set for the desktop If the index is too large, it is simply ignored. */ - void setDesktopName(long i, const otk::ustring &name); + void setDesktopName(unsigned int i, const otk::ustring &name); void installColormap(bool install) const;