1 // Windowmenu.cc for Openbox
2 // Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
3 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
23 // stupid macros needed to access some functions in version 2 of the GNU C
30 # include "../config.h"
31 #endif // HAVE_CONFIG_H
37 #include "Windowmenu.h"
38 #include "Workspace.h"
42 #endif // STDC_HEADERS
45 Windowmenu::Windowmenu(OpenboxWindow &win) : Basemenu(*win.getScreen()),
46 window(win), screen(*win.getScreen())
49 setTitleVisibility(False);
53 sendToMenu = new SendtoWorkspacemenu(*this);
54 insert(i18n->getMessage(WindowmenuSet, WindowmenuSendTo, "Send To ..."),
56 insert(i18n->getMessage(WindowmenuSet, WindowmenuShade, "Shade"),
57 BScreen::WindowShade);
58 insert(i18n->getMessage(WindowmenuSet, WindowmenuIconify, "Iconify"),
59 BScreen::WindowIconify);
60 insert(i18n->getMessage(WindowmenuSet, WindowmenuMaximize, "Maximize"),
61 BScreen::WindowMaximize);
62 insert(i18n->getMessage(WindowmenuSet, WindowmenuRaise,"Raise"),
63 BScreen::WindowRaise);
64 insert(i18n->getMessage(WindowmenuSet, WindowmenuLower, "Lower"),
65 BScreen::WindowLower);
66 insert(i18n->getMessage(WindowmenuSet, WindowmenuStick, "Stick"),
67 BScreen::WindowStick);
68 insert(i18n->getMessage(WindowmenuSet, WindowmenuKillClient, "Kill Client"),
70 insert(i18n->getMessage(WindowmenuSet, WindowmenuClose, "Close"),
71 BScreen::WindowClose);
75 setItemEnabled(1, window.hasTitlebar());
76 setItemEnabled(2, window.isIconifiable());
77 setItemEnabled(3, window.isMaximizable());
78 setItemEnabled(8, window.isClosable());
82 Windowmenu::~Windowmenu(void) {
87 void Windowmenu::show(void) {
88 if (isItemEnabled(1)) setItemSelected(1, window.isShaded());
89 if (isItemEnabled(3)) setItemSelected(3, window.isMaximized());
90 if (isItemEnabled(6)) setItemSelected(6, window.isStuck());
96 void Windowmenu::itemSelected(int button, int index) {
97 BasemenuItem *item = find(index);
99 /* Added by Scott Moynes, April 8, 2002
100 Ignore the middle button for every item except the maximize
101 button in the window menu. Maximize needs it for
102 horizontal/vertical maximize, however, for the others it is
103 inconsistent with the rest of the window behaviour.
107 switch (item->function()) {
108 case BScreen::WindowShade:
112 case BScreen::WindowIconify:
116 case BScreen::WindowMaximize:
117 window.maximize((unsigned int) button);
120 case BScreen::WindowClose:
124 case BScreen::WindowRaise:
125 screen.getWorkspace(window.getWorkspaceNumber())->raiseWindow(&window);
128 case BScreen::WindowLower:
129 screen.getWorkspace(window.getWorkspaceNumber())->lowerWindow(&window);
132 case BScreen::WindowStick:
136 case BScreen::WindowKill:
137 XKillClient(screen.getBaseDisplay().getXDisplay(),
138 window.getClientWindow());
141 } else if (item->function() == BScreen::WindowMaximize) {
143 window.maximize((unsigned int) button);
148 void Windowmenu::reconfigure(void) {
149 setItemEnabled(1, window.hasTitlebar());
150 setItemEnabled(2, window.isIconifiable());
151 setItemEnabled(3, window.isMaximizable());
152 setItemEnabled(8, window.isClosable());
154 sendToMenu->reconfigure();
156 Basemenu::reconfigure();
160 Windowmenu::SendtoWorkspacemenu::SendtoWorkspacemenu(Windowmenu &w)
161 : Basemenu(w.screen), windowmenu(w) {
162 setTitleVisibility(False);
169 void Windowmenu::SendtoWorkspacemenu::itemSelected(int button, int index) {
170 if (button > 2) return;
172 if (index <= windowmenu.screen.getWorkspaceCount()) {
173 if (index == windowmenu.screen.getCurrentWorkspaceID()) return;
174 if (windowmenu.window.isStuck()) windowmenu.window.stick();
176 if (button == 1) windowmenu.window.withdraw();
177 windowmenu.screen.reassociateWindow(&(windowmenu.window), index, True);
178 if (button == 2) windowmenu.screen.changeWorkspaceID(index);
184 void Windowmenu::SendtoWorkspacemenu::update(void) {
185 int i, r = getCount();
188 for (i = 0; i < r; ++i)
191 for (i = 0; i < windowmenu.screen.getWorkspaceCount(); ++i)
192 insert(windowmenu.screen.getWorkspace(i)->getName());
198 void Windowmenu::SendtoWorkspacemenu::show(void) {