]> icculus.org git repositories - mikachu/openbox.git/blob - src/Windowmenu.cc
fix compiling with --disable-nls
[mikachu/openbox.git] / src / Windowmenu.cc
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)
4 //
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:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
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.
22
23 // stupid macros needed to access some functions in version 2 of the GNU C
24 // library
25 #ifndef   _GNU_SOURCE
26 #define   _GNU_SOURCE
27 #endif // _GNU_SOURCE
28
29 #ifdef    HAVE_CONFIG_H
30 #  include "../config.h"
31 #endif // HAVE_CONFIG_H
32
33 #include "i18n.h"
34 #include "openbox.h"
35 #include "Screen.h"
36 #include "Window.h"
37 #include "Windowmenu.h"
38 #include "Workspace.h"
39
40 #ifdef    HAVE_STRING_H
41 #  include <string.h>
42 #endif // HAVE_STRING_H
43
44
45 Windowmenu::Windowmenu(OpenboxWindow &win) : Basemenu(*win.getScreen()),
46 window(win), screen(*win.getScreen())
47 {
48
49   setTitleVisibility(False);
50   setMovable(False);
51   setInternalMenu();
52
53   sendToMenu = new SendtoWorkspacemenu(*this);
54   insert(i18n(WindowmenuSet, WindowmenuSendTo, "Send To ..."),
55          sendToMenu);
56   insert(i18n(WindowmenuSet, WindowmenuShade, "Shade"),
57          BScreen::WindowShade);
58   insert(i18n(WindowmenuSet, WindowmenuIconify, "Iconify"),
59          BScreen::WindowIconify);
60   insert(i18n(WindowmenuSet, WindowmenuMaximize, "Maximize"),
61          BScreen::WindowMaximize);
62   insert(i18n(WindowmenuSet, WindowmenuRaise,"Raise"),
63          BScreen::WindowRaise);
64   insert(i18n(WindowmenuSet, WindowmenuLower, "Lower"),
65          BScreen::WindowLower);
66   insert(i18n(WindowmenuSet, WindowmenuStick, "Stick"),
67          BScreen::WindowStick);
68   insert(i18n(WindowmenuSet, WindowmenuKillClient, "Kill Client"),
69          BScreen::WindowKill);
70   insert(i18n(WindowmenuSet, WindowmenuClose, "Close"),
71          BScreen::WindowClose);
72
73   update();
74
75   setItemEnabled(1, window.hasTitlebar());
76   setItemEnabled(2, window.isIconifiable());
77   setItemEnabled(3, window.isMaximizable());
78   setItemEnabled(8, window.isClosable());
79 }
80
81
82 Windowmenu::~Windowmenu(void) {
83   delete sendToMenu;
84 }
85
86
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());
91
92   Basemenu::show();
93 }
94
95
96 void Windowmenu::itemSelected(int button, int index) {
97   BasemenuItem *item = find(index);
98
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.
104      */
105   if(button != 2) {
106     hide();
107     switch (item->function()) {
108     case BScreen::WindowShade:
109       window.shade();
110       break;
111
112     case BScreen::WindowIconify:
113       window.iconify();
114       break;
115
116     case BScreen::WindowMaximize:
117       window.maximize((unsigned int) button);
118       break;
119
120     case BScreen::WindowClose:
121       window.close();
122       break;
123
124     case BScreen::WindowRaise:
125       screen.getWorkspace(window.getWorkspaceNumber())->raiseWindow(&window);
126       break;
127
128     case BScreen::WindowLower:
129       screen.getWorkspace(window.getWorkspaceNumber())->lowerWindow(&window);
130       break;
131
132     case BScreen::WindowStick:
133       window.stick();
134       break;
135
136     case BScreen::WindowKill:
137       XKillClient(screen.getBaseDisplay().getXDisplay(),
138                   window.getClientWindow());
139       break;
140     }
141   } else if (item->function() == BScreen::WindowMaximize) {
142     hide();
143     window.maximize((unsigned int) button);
144   }
145 }
146
147
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());
153
154   sendToMenu->reconfigure();
155
156   Basemenu::reconfigure();
157 }
158
159
160 Windowmenu::SendtoWorkspacemenu::SendtoWorkspacemenu(Windowmenu &w)
161   : Basemenu(w.screen), windowmenu(w) {
162     setTitleVisibility(False);
163     setMovable(False);
164     setInternalMenu();
165     update();
166   }
167
168
169 void Windowmenu::SendtoWorkspacemenu::itemSelected(int button, int index) {
170   if (button > 2) return;
171
172   if (index <= windowmenu.screen.getWorkspaceCount()) {
173     if (index == windowmenu.screen.getCurrentWorkspaceID()) return;
174     if (windowmenu.window.isStuck()) windowmenu.window.stick();
175
176     if (button == 1) windowmenu.window.withdraw();
177     windowmenu.screen.reassociateWindow(&(windowmenu.window), index, True);
178     if (button == 2) windowmenu.screen.changeWorkspaceID(index);
179   }
180   hide();
181 }
182
183
184 void Windowmenu::SendtoWorkspacemenu::update(void) {
185   int i, r = getCount();
186
187   if (r != 0)
188     for (i = 0; i < r; ++i)
189       remove(0);
190
191   for (i = 0; i < windowmenu.screen.getWorkspaceCount(); ++i)
192     insert(windowmenu.screen.getWorkspace(i)->getName());
193
194   Basemenu::update();
195 }
196
197
198 void Windowmenu::SendtoWorkspacemenu::show(void) {
199   update();
200
201   Basemenu::show();
202 }