aboutsummaryrefslogtreecommitdiff
path: root/src/Windowmenu.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/Windowmenu.cc')
-rw-r--r--src/Windowmenu.cc377
1 files changed, 179 insertions, 198 deletions
diff --git a/src/Windowmenu.cc b/src/Windowmenu.cc
index 159f090..a6611a0 100644
--- a/src/Windowmenu.cc
+++ b/src/Windowmenu.cc
@@ -1,3 +1,5 @@
1// Windowmenu.cc for Fluxbox
2// Copyright (c) 2001-2002 Henrik Kinnunen (fluxgen@linuxmail.org)
1// Windowmenu.cc for Blackbox - an X11 Window manager 3// Windowmenu.cc for Blackbox - an X11 Window manager
2// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) 4// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
3// 5//
@@ -19,14 +21,15 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 22// DEALINGS IN THE SOFTWARE.
21 23
22// stupid macros needed to access some functions in version 2 of the GNU C 24// $Id: Windowmenu.cc,v 1.17 2002/08/31 10:42:25 fluxgen Exp $
23// library 25
24#ifndef _GNU_SOURCE 26//use GNU extensions
25#define _GNU_SOURCE 27#ifndef _GNU_SOURCE
28#define _GNU_SOURCE
26#endif // _GNU_SOURCE 29#endif // _GNU_SOURCE
27 30
28#ifdef HAVE_CONFIG_H 31#ifdef HAVE_CONFIG_H
29# include "../config.h" 32#include "../config.h"
30#endif // HAVE_CONFIG_H 33#endif // HAVE_CONFIG_H
31 34
32#include "i18n.hh" 35#include "i18n.hh"
@@ -36,254 +39,231 @@
36#include "Windowmenu.hh" 39#include "Windowmenu.hh"
37#include "Workspace.hh" 40#include "Workspace.hh"
38 41
39#ifdef STDC_HEADERS 42#ifdef STDC_HEADERS
40# include <string.h> 43#include <string.h>
41#endif // STDC_HEADERS 44#endif // STDC_HEADERS
42 45
43 46
44Windowmenu::Windowmenu(FluxboxWindow *win) : Basemenu(win->getScreen()) { 47Windowmenu::Windowmenu(FluxboxWindow *win) : Basemenu(win->getScreen()),
45 window = win; 48window(win),
46 screen = window->getScreen(); 49screen(window->getScreen()){
47 50
48 setTitleVisibility(False); 51 setTitleVisibility(False);
49 setMovable(False); 52 setMovable(False);
50 setInternalMenu(); 53 setInternalMenu();
51 54
52 I18n *i18n = I18n::instance(); 55 I18n *i18n = I18n::instance();
53 56
54 sendToMenu = new SendtoWorkspacemenu(this); 57 sendToMenu = new SendtoWorkspacemenu(this);
55 sendGroupToMenu = new SendGroupToWorkspacemenu(this); 58 sendGroupToMenu = new SendGroupToWorkspacemenu(this);
56 59 using namespace FBNLS;
57 insert(i18n->getMessage( 60 insert(i18n->getMessage(
58#ifdef NLS 61 WindowmenuSet, WindowmenuSendTo,
59 WindowmenuSet, WindowmenuSendTo, 62 "Send To ..."),
60#else // !NLS
61 0, 0,
62#endif // NLS
63 "Send To ..."),
64 sendToMenu); 63 sendToMenu);
65 64
66 insert(i18n->getMessage( 65 insert(i18n->getMessage(
67#ifdef NLS 66 WindowmenuSet, WindowmenuSendGroupTo,
68 WindowmenuSet, WindowmenuSendGroupTo, 67 "Send Group To ..."),
69#else // !NLS 68 sendGroupToMenu);
70 0, 0,
71#endif // NLS
72 "Send Group To ..."),
73 sendGroupToMenu);
74 69
75 insert(i18n->getMessage( 70 insert(i18n->getMessage(
76#ifdef NLS 71 WindowmenuSet, WindowmenuShade,
77 WindowmenuSet, WindowmenuShade, 72 "Shade"),
78#else // !NLS 73 BScreen::WINDOWSHADE);
79 0, 0, 74 insert(i18n->getMessage(
80#endif // NLS 75 WindowmenuSet, WindowmenuIconify,
81 "Shade"), 76 "Iconify"),
82 BScreen::WindowShade); 77 BScreen::WINDOWICONIFY);
83 insert(i18n->getMessage( 78 insert(i18n->getMessage(
84#ifdef NLS 79 WindowmenuSet, WindowmenuMaximize,
85 WindowmenuSet, WindowmenuIconify, 80 "Maximize"),
86#else // !NLS 81 BScreen::WINDOWMAXIMIZE);
87 0, 0, 82 insert(i18n->getMessage(
88#endif // NLS 83 WindowmenuSet, WindowmenuRaise,
89 "Iconify"), 84 "Raise"),
90 BScreen::WindowIconify); 85 BScreen::WINDOWRAISE);
91 insert(i18n->getMessage( 86 insert(i18n->getMessage(
92#ifdef NLS 87 WindowmenuSet, WindowmenuLower,
93 WindowmenuSet, WindowmenuMaximize, 88 "Lower"),
94#else // !NLS 89 BScreen::WINDOWLOWER);
95 0, 0, 90 insert(i18n->getMessage(
96#endif // NLS 91 WindowmenuSet, WindowmenuStick,
97 "Maximize"), 92 "Stick"),
98 BScreen::WindowMaximize); 93 BScreen::WINDOWSTICK);
99 insert(i18n->getMessage( 94 insert(i18n->getMessage(
100#ifdef NLS 95 WindowmenuSet, WindowmenuKillClient,
101 WindowmenuSet, WindowmenuRaise, 96 "Kill Client"),
102#else // !NLS 97 BScreen::WINDOWKILL);
103 0, 0, 98 insert(i18n->getMessage(
104#endif // NLS 99 WindowmenuSet, WindowmenuClose,
105 "Raise"), 100 "Close"),
106 BScreen::WindowRaise); 101 BScreen::WINDOWCLOSE);
107 insert(i18n->getMessage( 102 insert(i18n->getMessage(
108#ifdef NLS 103 WindowmenuSet, WindowmenuTab,
109 WindowmenuSet, WindowmenuLower, 104 "Tab"),
110#else // !NLS 105 BScreen::WINDOWTAB);
111 0, 0, 106
112#endif // NLS 107 update();
113 "Lower"), 108
114 BScreen::WindowLower); 109 setItemEnabled(2, window->hasTitlebar());
115 insert(i18n->getMessage( 110 setItemEnabled(3, window->isIconifiable());
116#ifdef NLS 111 setItemEnabled(4, window->isMaximizable());
117 WindowmenuSet, WindowmenuStick, 112 setItemEnabled(9, window->isClosable());
118#else // !NLS 113 setItemEnabled(10, true); //we should always be able to enable the tab
119 0, 0,
120#endif // NLS
121 "Stick"),
122 BScreen::WindowStick);
123 insert(i18n->getMessage(
124#ifdef NLS
125 WindowmenuSet, WindowmenuKillClient,
126#else // !NLS
127 0, 0,
128#endif // NLS
129 "Kill Client"),
130 BScreen::WindowKill);
131 insert(i18n->getMessage(
132#ifdef NLS
133 WindowmenuSet, WindowmenuClose,
134#else // !NLS
135 0, 0,
136#endif // NLS
137 "Close"),
138 BScreen::WindowClose);
139
140 //TODO: nls
141 insert("Tab", BScreen::WindowTab);
142
143 update();
144 114
145 setItemEnabled(1, window->hasTitlebar());
146 setItemEnabled(2, window->isIconifiable());
147 setItemEnabled(3, window->isMaximizable());
148 setItemEnabled(8, window->isClosable());
149 setItemEnabled(9, window->hasTab());
150} 115}
151 116
152 117
153Windowmenu::~Windowmenu(void) { 118Windowmenu::~Windowmenu(void) {
154 delete sendToMenu; 119 delete sendToMenu;
155 delete sendGroupToMenu; 120 delete sendGroupToMenu;
156} 121}
157 122
158 123
159void Windowmenu::show(void) { 124void Windowmenu::show(void) {
160 if (isItemEnabled(1)) setItemSelected(1, window->isShaded()); 125 if (isItemEnabled(2)) setItemSelected(2, window->isShaded());
161 if (isItemEnabled(3)) setItemSelected(3, window->isMaximized()); 126 if (isItemEnabled(4)) setItemSelected(4, window->isMaximized());
162 if (isItemEnabled(6)) setItemSelected(6, window->isStuck()); 127 if (isItemEnabled(7)) setItemSelected(7, window->isStuck());
163 128
164 Basemenu::show(); 129 Basemenu::show();
165} 130}
166 131
167 132
168void Windowmenu::itemSelected(int button, int index) { 133void Windowmenu::itemSelected(int button, unsigned int index) {
169 BasemenuItem *item = find(index); 134 BasemenuItem *item = find(index);
170 135 hide();
171 switch (item->function()) { 136 switch (item->function()) {
172 case BScreen::WindowShade: 137 case BScreen::WINDOWSHADE:
173 hide(); 138 if (window->isIconic())
174 if (window->getTab()) 139 break;
140
141 window->shade();
142 if (window->hasTab())
175 window->getTab()->shade(); 143 window->getTab()->shade();
176 window->shade(); 144 break;
177 break; 145
178 146 case BScreen::WINDOWICONIFY:
179 case BScreen::WindowIconify: 147 if (!window->isIconic())
180 hide(); 148 window->iconify();
181 window->iconify(); 149 else
182 break; 150 window->deiconify(); // restore window
183 151
184 case BScreen::WindowMaximize: 152 break;
185 hide(); 153
186 window->maximize((unsigned int) button); 154 case BScreen::WINDOWMAXIMIZE:
187 break; 155 window->maximize((unsigned int) button);
188 156 break;
189 case BScreen::WindowClose: 157
190 hide(); 158 case BScreen::WINDOWCLOSE:
191 window->close(); 159 window->close();
192 break; 160 break;
193 161
194 case BScreen::WindowRaise: 162 case BScreen::WINDOWRAISE:
195 hide(); 163 if (window->isIconic())
196 screen->getWorkspace(window->getWorkspaceNumber())->raiseWindow(window); 164 break;
197 break; 165
198 166 if (window->hasTab())
199 case BScreen::WindowLower: 167 window->getTab()->raise(); //raise tabs
200 hide(); 168 screen->getWorkspace(window->getWorkspaceNumber())->raiseWindow(window);
201 screen->getWorkspace(window->getWorkspaceNumber())->lowerWindow(window); 169 break;
202 break; 170
203 171 case BScreen::WINDOWLOWER:
204 case BScreen::WindowStick: 172 if (window->isIconic())
205 hide(); 173 break;
206 window->stick(); 174
207 break; 175 screen->getWorkspace(window->getWorkspaceNumber())->lowerWindow(window);
208 176 if (window->hasTab())
209 case BScreen::WindowKill: 177 window->getTab()->lower(); //lower tabs AND all it's windows
210 hide(); 178 break;
211 XKillClient(screen->getBaseDisplay()->getXDisplay(), 179
212 window->getClientWindow()); 180 case BScreen::WINDOWSTICK:
213 break; 181 window->stick();
214 case BScreen::WindowTab: 182 break;
215 hide(); 183
184 case BScreen::WINDOWKILL:
185 XKillClient(screen->getBaseDisplay()->getXDisplay(),
186 window->getClientWindow());
187 break;
188 case BScreen::WINDOWTAB:
216 window->setTab(!window->hasTab()); 189 window->setTab(!window->hasTab());
217 break; 190 break;
218 } 191 }
219} 192}
220 193
221 194
222void Windowmenu::reconfigure(void) { 195void Windowmenu::reconfigure(void) {
223 setItemEnabled(1, window->hasTitlebar()); 196 setItemEnabled(1, window->hasTitlebar());
224 setItemEnabled(2, window->isIconifiable()); 197 setItemEnabled(2, window->isIconifiable());
225 setItemEnabled(3, window->isMaximizable()); 198 setItemEnabled(3, window->isMaximizable());
226 setItemEnabled(8, window->isClosable()); 199 setItemEnabled(8, window->isClosable());
227 200
228 sendToMenu->reconfigure(); 201 sendToMenu->reconfigure();
229 sendGroupToMenu->reconfigure(); 202 sendGroupToMenu->reconfigure();
230 203
231 Basemenu::reconfigure(); 204 Basemenu::reconfigure();
232} 205}
233 206
234 207
235Windowmenu::SendtoWorkspacemenu::SendtoWorkspacemenu(Windowmenu *w) 208Windowmenu::SendtoWorkspacemenu::SendtoWorkspacemenu(Windowmenu *w)
236 : Basemenu(w->screen) 209 : Basemenu(w->screen)
237{ 210{
238 windowmenu = w; 211 windowmenu = w;
239 212
240 setTitleVisibility(False); 213 setTitleVisibility(False);
241 setMovable(False); 214 setMovable(False);
242 setInternalMenu(); 215 setInternalMenu();
243 update(); 216 update();
244} 217}
245 218
246 219
247void Windowmenu::SendtoWorkspacemenu::itemSelected(int button, int index) { 220void Windowmenu::SendtoWorkspacemenu::itemSelected(int button, unsigned int index) {
248 if (button > 2) return; 221 if (button > 2) return;
249 222
250 if (index <= windowmenu->screen->getCount()) { 223 if (index <= windowmenu->screen->getCount()) {
251 if (index == windowmenu->screen->getCurrentWorkspaceID()) return; 224
252 if (windowmenu->window->isStuck()) windowmenu->window->stick(); 225 // no need to send it to a workspace it already exist on
226 if (index == windowmenu->screen->getCurrentWorkspaceID())
227 return;
228
229 // if the window is stuck then unstick it
230 if (windowmenu->window->isStuck())
231 windowmenu->window->stick();
253 232
254 if (button == 1) windowmenu->window->withdraw(); 233 if (button == 1) { // send to workspace without changing workspace
255 windowmenu->screen->reassociateWindow(windowmenu->window, index, True); 234 windowmenu->screen->sendToWorkspace(index,
256 if (windowmenu->window->getTab()) { 235 windowmenu->window, false);
257 windowmenu->window->getTab()->disconnect(); 236 } else if (button == 2) { // send to workspace and change workspace
258 windowmenu->window->getTab()->setPosition(); 237 windowmenu->screen->sendToWorkspace(index,
238 windowmenu->window, true);
259 } 239 }
260 if (button == 2) windowmenu->screen->changeWorkspaceID(index); 240 }
261 } 241
262 hide(); 242 hide();
263} 243}
264 244
265 245
266void Windowmenu::SendtoWorkspacemenu::update(void) { 246void Windowmenu::SendtoWorkspacemenu::update(void) {
267 int i, r = getCount(); 247 unsigned int i, r = numberOfItems();
268
269 if (getCount() != 0)
270 for (i = 0; i < r; ++i)
271 remove(0);
272 248
273 for (i = 0; i < windowmenu->screen->getCount(); ++i) 249 if (numberOfItems() != 0) {
274 insert(windowmenu->screen->getWorkspace(i)->getName()); 250 for (i = 0; i < r; ++i)
251 remove(0);
252 }
253 for (i = 0; i < windowmenu->screen->getCount(); ++i)
254 insert(windowmenu->screen->getWorkspace(i)->name().c_str());
275 255
276 Basemenu::update(); 256 Basemenu::update();
277} 257}
278 258
279 259
280void Windowmenu::SendtoWorkspacemenu::show(void) { 260void Windowmenu::SendtoWorkspacemenu::show(void) {
281 update(); 261 update();
282 262
283 Basemenu::show(); 263 Basemenu::show();
284} 264}
285 265
286void Windowmenu::SendGroupToWorkspacemenu::itemSelected(int button, int index) { 266void Windowmenu::SendGroupToWorkspacemenu::itemSelected(int button, unsigned int index) {
287 if (button > 2) 267 if (button > 2)
288 return; 268 return;
289 269
@@ -294,15 +274,16 @@ void Windowmenu::SendGroupToWorkspacemenu::itemSelected(int button, int index) {
294 getWindowMenu()->window->stick(); 274 getWindowMenu()->window->stick();
295 275
296 if (button == 1) { 276 if (button == 1) {
277 // TODO: use reassociateGroup from BScreen instead
297 if (getWindowMenu()->window->hasTab()) { 278 if (getWindowMenu()->window->hasTab()) {
298 for (Tab *first = Tab::getFirst(getWindowMenu()->window->getTab()); 279 for (Tab *first = Tab::getFirst(getWindowMenu()->window->getTab());
299 first!=0; first=first->next()) { 280 first!=0; first=first->next()) {
300 first->withdraw(); 281 first->withdraw();
301 first->getWindow()->withdraw(); 282 first->getWindow()->withdraw();
302 getWindowMenu()->screen->reassociateWindow(first->getWindow(), index, True); 283 getWindowMenu()->screen->reassociateWindow(first->getWindow(), index, True);
303 284
304 } 285 }
305 } else { 286 } else {
306 getWindowMenu()->window->withdraw(); 287 getWindowMenu()->window->withdraw();
307 getWindowMenu()->screen->reassociateWindow(getWindowMenu()->window, index, True); 288 getWindowMenu()->screen->reassociateWindow(getWindowMenu()->window, index, True);
308 } 289 }