Change to the linux kernel coding style
[wmaker-crm.git] / src / winmenu.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001/* winmenu.c - command menu for windows
6830b057 dan2004-10-12 21:28:27 +00002 *
9af1c6c4 dan1998-10-21 14:43:47 +00003 * Window Maker window manager
6830b057 dan2004-10-12 21:28:27 +00004 *
4153e2fd dan2003-01-16 23:30:45 +00005 * Copyright (c) 1997-2003 Alfredo K. Kojima
6830b057 dan2004-10-12 21:28:27 +00006 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00007 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
6830b057 dan2004-10-12 21:28:27 +000019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
9d2e6ef9 scottc1998-09-29 22:36:29 +000020 * USA.
21 */
22
23#include "wconfig.h"
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <unistd.h>
28#include <string.h>
29
30#include <X11/Xlib.h>
31#include <X11/Xutil.h>
32
33#include "WindowMaker.h"
34#include "actions.h"
35#include "menu.h"
6830b057 dan2004-10-12 21:28:27 +000036#include "funcs.h"
9d2e6ef9 scottc1998-09-29 22:36:29 +000037#include "window.h"
38#include "client.h"
39#include "application.h"
40#include "keybind.h"
41#include "framewin.h"
42#include "workspace.h"
43#include "winspector.h"
44#include "dialog.h"
0261c326 dan1999-01-06 15:22:33 +000045#include "stacking.h"
e7495baf dan1999-02-17 11:06:40 +000046#include "icon.h"
3c046182 kojima1999-09-16 02:58:56 +000047
9d2e6ef9 scottc1998-09-29 22:36:29 +000048#define MC_MAXIMIZE 0
49#define MC_MINIATURIZE 1
50#define MC_SHADE 2
51#define MC_HIDE 3
6de693a2 kojima2004-10-21 00:59:52 +000052#define MC_MOVERESIZE 4
53#define MC_SELECT 5
54#define MC_DUMMY_MOVETO 6
55#define MC_PROPERTIES 7
56#define MC_OPTIONS 8
57#define MC_SHORTCUT 8
9d2e6ef9 scottc1998-09-29 22:36:29 +000058
6de693a2 kojima2004-10-21 00:59:52 +000059#define MC_CLOSE 9
60#define MC_KILL 10
9d2e6ef9 scottc1998-09-29 22:36:29 +000061
0261c326 dan1999-01-06 15:22:33 +000062#define WO_KEEP_ON_TOP 0
63#define WO_KEEP_AT_BOTTOM 1
64#define WO_OMNIPRESENT 2
65#define WO_ENTRIES 3
9d2e6ef9 scottc1998-09-29 22:36:29 +000066
67/**** Global data ***/
68extern Time LastTimestamp;
69extern Atom _XA_WM_DELETE_WINDOW;
9af1c6c4 dan1998-10-21 14:43:47 +000070extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
9d2e6ef9 scottc1998-09-29 22:36:29 +000071
72extern WShortKey wKeyBindings[WKBD_LAST];
73
74extern WPreferences wPreferences;
75
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020076static void updateOptionsMenu(WMenu * menu, WWindow * wwin);
0261c326 dan1999-01-06 15:22:33 +000077
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020078static void execWindowOptionCommand(WMenu * menu, WMenuEntry * entry)
0261c326 dan1999-01-06 15:22:33 +000079{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020080 WWindow *wwin = (WWindow *) entry->clientdata;
81
82 switch (entry->order) {
83 case WO_KEEP_ON_TOP:
84 if (wwin->frame->core->stacking->window_level != WMFloatingLevel)
85 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
86 else
87 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
88 break;
89
90 case WO_KEEP_AT_BOTTOM:
91 if (wwin->frame->core->stacking->window_level != WMSunkenLevel)
92 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
93 else
94 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
95 break;
96
97 case WO_OMNIPRESENT:
98 wWindowSetOmnipresent(wwin, !wwin->flags.omnipresent);
99 break;
100 }
0261c326 dan1999-01-06 15:22:33 +0000101}
102
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200103static void execMenuCommand(WMenu * menu, WMenuEntry * entry)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000104{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200105 WWindow *wwin = (WWindow *) entry->clientdata;
106 WApplication *wapp;
107
108 CloseWindowMenu(menu->frame->screen_ptr);
109
110 switch (entry->order) {
111 case MC_CLOSE:
112 /* send delete message */
113 wClientSendProtocol(wwin, _XA_WM_DELETE_WINDOW, LastTimestamp);
114 break;
115
116 case MC_KILL:
117 wretain(wwin);
118 if (wPreferences.dont_confirm_kill
119 || wMessageDialog(menu->frame->screen_ptr, _("Kill Application"),
120 _
121 ("This will kill the application.\nAny unsaved changes will be lost.\nPlease confirm."),
122 _("Yes"), _("No"), NULL) == WAPRDefault) {
123 if (!wwin->flags.destroyed)
124 wClientKill(wwin);
125 }
126 wrelease(wwin);
127 break;
128
129 case MC_MINIATURIZE:
130 if (wwin->flags.miniaturized) {
131 wDeiconifyWindow(wwin);
132 } else {
133 if (wwin->protocols.MINIATURIZE_WINDOW) {
134 wClientSendProtocol(wwin, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW, LastTimestamp);
135 } else {
136 wIconifyWindow(wwin);
137 }
138 }
139 break;
140
141 case MC_MAXIMIZE:
142 if (wwin->flags.maximized)
143 wUnmaximizeWindow(wwin);
144 else
145 wMaximizeWindow(wwin, MAX_VERTICAL | MAX_HORIZONTAL);
146 break;
147
148 case MC_SHADE:
149 if (wwin->flags.shaded)
150 wUnshadeWindow(wwin);
151 else
152 wShadeWindow(wwin);
153 break;
154
155 case MC_SELECT:
156 if (!wwin->flags.miniaturized)
157 wSelectWindow(wwin, !wwin->flags.selected);
158 else
159 wIconSelect(wwin->icon);
160 break;
161
162 case MC_MOVERESIZE:
163 wKeyboardMoveResizeWindow(wwin);
164 break;
165
166 case MC_PROPERTIES:
167 wShowInspectorForWindow(wwin);
168 break;
169
170 case MC_HIDE:
171 wapp = wApplicationOf(wwin->main_window);
172 wHideApplication(wapp);
173 break;
174 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000175}
176
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200177static void switchWSCommand(WMenu * menu, WMenuEntry * entry)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000178{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200179 WWindow *wwin = (WWindow *) entry->clientdata;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000180
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200181 wSelectWindow(wwin, False);
182 wWindowChangeWorkspace(wwin, entry->order);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000183}
184
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200185static void makeShortcutCommand(WMenu * menu, WMenuEntry * entry)
59eb9475 dan1998-11-03 12:53:26 +0000186{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200187 WWindow *wwin = (WWindow *) entry->clientdata;
188 WScreen *scr = wwin->screen_ptr;
189 int index = entry->order - WO_ENTRIES;
190
191 if (scr->shortcutWindows[index]) {
192 WMFreeArray(scr->shortcutWindows[index]);
193 scr->shortcutWindows[index] = NULL;
194 }
195
196 if (wwin->flags.selected && scr->selected_windows) {
197 scr->shortcutWindows[index] = WMDuplicateArray(scr->selected_windows);
198 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
199 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
200 } else {
201 scr->shortcutWindows[index] = WMCreateArray(4);
202 WMAddToArray(scr->shortcutWindows[index], wwin);
203 }
204
205 wSelectWindow(wwin, !wwin->flags.selected);
206 XFlush(dpy);
207 wusleep(3000);
208 wSelectWindow(wwin, !wwin->flags.selected);
209 XFlush(dpy);
59eb9475 dan1998-11-03 12:53:26 +0000210}
211
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200212static void updateWorkspaceMenu(WMenu * menu)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000213{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200214 WScreen *scr = menu->frame->screen_ptr;
215 char title[MAX_WORKSPACENAME_WIDTH + 1];
216 int i;
217
218 if (!menu)
219 return;
220
221 for (i = 0; i < scr->workspace_count; i++) {
222 if (i < menu->entry_no) {
223 if (strcmp(menu->entries[i]->text, scr->workspaces[i]->name) != 0) {
224 wfree(menu->entries[i]->text);
225 strncpy(title, scr->workspaces[i]->name, MAX_WORKSPACENAME_WIDTH);
226 title[MAX_WORKSPACENAME_WIDTH] = 0;
227 menu->entries[i]->text = wstrdup(title);
228 menu->flags.realized = 0;
229 }
230 } else {
231 strncpy(title, scr->workspaces[i]->name, MAX_WORKSPACENAME_WIDTH);
232 title[MAX_WORKSPACENAME_WIDTH] = 0;
233
234 wMenuAddCallback(menu, title, switchWSCommand, NULL);
235
236 menu->flags.realized = 0;
237 }
238 }
239
240 if (!menu->flags.realized)
241 wMenuRealize(menu);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000242}
243
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200244static void updateMakeShortcutMenu(WMenu * menu, WWindow * wwin)
59eb9475 dan1998-11-03 12:53:26 +0000245{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200246 WMenu *smenu = menu->cascades[menu->entries[MC_SHORTCUT]->cascade];
247 int i;
248 char *buffer;
249 int buflen;
250 KeyCode kcode;
251
252 if (!smenu)
253 return;
254
255 buflen = strlen(_("Set Shortcut")) + 16;
256 buffer = wmalloc(buflen);
257
258 for (i = WO_ENTRIES; i < smenu->entry_no; i++) {
259 char *tmp;
260 int shortcutNo = i - WO_ENTRIES;
261 WMenuEntry *entry = smenu->entries[i];
262 WMArray *shortSelWindows = wwin->screen_ptr->shortcutWindows[shortcutNo];
263
264 snprintf(buffer, buflen, "%s %i", _("Set Shortcut"), shortcutNo + 1);
265
266 if (!shortSelWindows) {
267 entry->flags.indicator_on = 0;
268 } else {
269 entry->flags.indicator_on = 1;
270 if (WMCountInArray(shortSelWindows, wwin))
271 entry->flags.indicator_type = MI_DIAMOND;
272 else
273 entry->flags.indicator_type = MI_CHECK;
274 }
275
276 if (strcmp(buffer, entry->text) != 0) {
277 wfree(entry->text);
278 entry->text = wstrdup(buffer);
279 smenu->flags.realized = 0;
280 }
281
282 kcode = wKeyBindings[WKBD_WINDOW1 + shortcutNo].keycode;
283
284 if (kcode) {
285 if ((tmp = XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0)))
286 && (!entry->rtext || strcmp(tmp, entry->rtext) != 0)) {
287 if (entry->rtext)
288 wfree(entry->rtext);
289 entry->rtext = wstrdup(tmp);
290 smenu->flags.realized = 0;
291 }
292 wMenuSetEnabled(smenu, i, True);
293 } else {
294 wMenuSetEnabled(smenu, i, False);
295 if (entry->rtext) {
296 wfree(entry->rtext);
297 entry->rtext = NULL;
298 smenu->flags.realized = 0;
299 }
300 }
301 entry->clientdata = wwin;
302 }
303 wfree(buffer);
304 if (!smenu->flags.realized)
305 wMenuRealize(smenu);
59eb9475 dan1998-11-03 12:53:26 +0000306}
307
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200308static void updateOptionsMenu(WMenu * menu, WWindow * wwin)
6830b057 dan2004-10-12 21:28:27 +0000309{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200310 WMenu *smenu = menu->cascades[menu->entries[MC_OPTIONS]->cascade];
311
312 /* keep on top check */
313 smenu->entries[WO_KEEP_ON_TOP]->clientdata = wwin;
314 smenu->entries[WO_KEEP_ON_TOP]->flags.indicator_on =
315 (wwin->frame->core->stacking->window_level == WMFloatingLevel) ? 1 : 0;
316 wMenuSetEnabled(smenu, WO_KEEP_ON_TOP, !wwin->flags.miniaturized);
317
318 /* keep at bottom check */
319 smenu->entries[WO_KEEP_AT_BOTTOM]->clientdata = wwin;
320 smenu->entries[WO_KEEP_AT_BOTTOM]->flags.indicator_on =
321 (wwin->frame->core->stacking->window_level == WMSunkenLevel) ? 1 : 0;
322 wMenuSetEnabled(smenu, WO_KEEP_AT_BOTTOM, !wwin->flags.miniaturized);
323
324 /* omnipresent check */
325 smenu->entries[WO_OMNIPRESENT]->clientdata = wwin;
326 smenu->entries[WO_OMNIPRESENT]->flags.indicator_on = IS_OMNIPRESENT(wwin);
327
328 smenu->flags.realized = 0;
329 wMenuRealize(smenu);
0261c326 dan1999-01-06 15:22:33 +0000330}
331
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200332static WMenu *makeWorkspaceMenu(WScreen * scr)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000333{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200334 WMenu *menu;
6830b057 dan2004-10-12 21:28:27 +0000335
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200336 menu = wMenuCreate(scr, NULL, False);
337 if (!menu) {
338 wwarning(_("could not create submenu for window menu"));
339 return NULL;
340 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000341
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200342 updateWorkspaceMenu(menu);
6830b057 dan2004-10-12 21:28:27 +0000343
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200344 return menu;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000345}
346
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200347static WMenu *makeMakeShortcutMenu(WScreen * scr, WMenu * menu)
0261c326 dan1999-01-06 15:22:33 +0000348{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200349 /*
350 WMenu *menu;
351 */
352 int i;
353 /*
354 menu = wMenuCreate(scr, NULL, False);
355 if (!menu) {
356 wwarning(_("could not create submenu for window menu"));
357 return NULL;
358 }
359 */
360
361 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
362 WMenuEntry *entry;
363 entry = wMenuAddCallback(menu, "", makeShortcutCommand, NULL);
364
365 entry->flags.indicator = 1;
366 }
367
368 return menu;
0261c326 dan1999-01-06 15:22:33 +0000369}
370
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200371static WMenu *makeOptionsMenu(WScreen * scr)
372{
373 WMenu *menu;
374 WMenuEntry *entry;
0261c326 dan1999-01-06 15:22:33 +0000375
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200376 menu = wMenuCreate(scr, NULL, False);
377 if (!menu) {
378 wwarning(_("could not create submenu for window menu"));
379 return NULL;
380 }
0261c326 dan1999-01-06 15:22:33 +0000381
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200382 entry = wMenuAddCallback(menu, _("Keep on top"), execWindowOptionCommand, NULL);
383 entry->flags.indicator = 1;
384 entry->flags.indicator_type = MI_CHECK;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000385
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200386 entry = wMenuAddCallback(menu, _("Keep at bottom"), execWindowOptionCommand, NULL);
387 entry->flags.indicator = 1;
388 entry->flags.indicator_type = MI_CHECK;
0261c326 dan1999-01-06 15:22:33 +0000389
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200390 entry = wMenuAddCallback(menu, _("Omnipresent"), execWindowOptionCommand, NULL);
391 entry->flags.indicator = 1;
392 entry->flags.indicator_type = MI_CHECK;
393
394 return menu;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000395}
396
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200397static WMenu *createWindowMenu(WScreen * scr)
398{
399 WMenu *menu;
400 KeyCode kcode;
401 WMenuEntry *entry;
402 char *tmp;
403
404 menu = wMenuCreate(scr, NULL, False);
405 /*
406 * Warning: If you make some change that affects the order of the
407 * entries, you must update the command #defines in the top of
408 * this file.
409 */
410 entry = wMenuAddCallback(menu, _("Maximize"), execMenuCommand, NULL);
411 if (wKeyBindings[WKBD_MAXIMIZE].keycode != 0) {
412 kcode = wKeyBindings[WKBD_MAXIMIZE].keycode;
413
414 if (kcode && (tmp = XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0))))
415 entry->rtext = wstrdup(tmp);
416 }
417
418 entry = wMenuAddCallback(menu, _("Miniaturize"), execMenuCommand, NULL);
419 if (wKeyBindings[WKBD_MINIATURIZE].keycode != 0) {
420 kcode = wKeyBindings[WKBD_MINIATURIZE].keycode;
421
422 if (kcode && (tmp = XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0))))
423 entry->rtext = wstrdup(tmp);
424 }
425
426 entry = wMenuAddCallback(menu, _("Shade"), execMenuCommand, NULL);
427 if (wKeyBindings[WKBD_SHADE].keycode != 0) {
428 kcode = wKeyBindings[WKBD_SHADE].keycode;
429
430 if (kcode && (tmp = XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0))))
431 entry->rtext = wstrdup(tmp);
432 }
433
434 entry = wMenuAddCallback(menu, _("Hide"), execMenuCommand, NULL);
435 if (wKeyBindings[WKBD_HIDE].keycode != 0) {
436 kcode = wKeyBindings[WKBD_HIDE].keycode;
437
438 if (kcode && (tmp = XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0))))
439 entry->rtext = wstrdup(tmp);
440 }
441
442 entry = wMenuAddCallback(menu, _("Resize/Move"), execMenuCommand, NULL);
443 if (wKeyBindings[WKBD_MOVERESIZE].keycode != 0) {
444 kcode = wKeyBindings[WKBD_MOVERESIZE].keycode;
445
446 if (kcode && (tmp = XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0))))
447 entry->rtext = wstrdup(tmp);
448 }
449
450 entry = wMenuAddCallback(menu, _("Select"), execMenuCommand, NULL);
451 if (wKeyBindings[WKBD_SELECT].keycode != 0) {
452 kcode = wKeyBindings[WKBD_SELECT].keycode;
453
454 if (kcode && (tmp = XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0))))
455 entry->rtext = wstrdup(tmp);
456 }
457
458 entry = wMenuAddCallback(menu, _("Move To"), NULL, NULL);
459 scr->workspace_submenu = makeWorkspaceMenu(scr);
460 if (scr->workspace_submenu)
461 wMenuEntrySetCascade(menu, entry, scr->workspace_submenu);
462
463 entry = wMenuAddCallback(menu, _("Attributes..."), execMenuCommand, NULL);
464
465 entry = wMenuAddCallback(menu, _("Options"), NULL, NULL);
466 wMenuEntrySetCascade(menu, entry, makeMakeShortcutMenu(scr, makeOptionsMenu(scr)));
467
468 /*
469 entry = wMenuAddCallback(menu, _("Select Shortcut"), NULL, NULL);
470 wMenuEntrySetCascade(menu, entry, makeMakeShortcutMenu(scr));
471 */
472
473 entry = wMenuAddCallback(menu, _("Close"), execMenuCommand, NULL);
474 if (wKeyBindings[WKBD_CLOSE].keycode != 0) {
475 kcode = wKeyBindings[WKBD_CLOSE].keycode;
476 if (kcode && (tmp = XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0))))
477 entry->rtext = wstrdup(tmp);
478 }
479
480 entry = wMenuAddCallback(menu, _("Kill"), execMenuCommand, NULL);
481
482 return menu;
483}
9d2e6ef9 scottc1998-09-29 22:36:29 +0000484
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200485void CloseWindowMenu(WScreen * scr)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000486{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200487 if (scr->window_menu) {
488 if (scr->window_menu->flags.mapped)
489 wMenuUnmap(scr->window_menu);
6830b057 dan2004-10-12 21:28:27 +0000490
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200491 if (scr->window_menu->entries[0]->clientdata) {
492 WWindow *wwin = (WWindow *) scr->window_menu->entries[0]->clientdata;
6830b057 dan2004-10-12 21:28:27 +0000493
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200494 wwin->flags.menu_open_for_me = 0;
495 }
496 scr->window_menu->entries[0]->clientdata = NULL;
497 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000498}
499
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200500static void updateMenuForWindow(WMenu * menu, WWindow * wwin)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000501{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200502 WApplication *wapp = wApplicationOf(wwin->main_window);
503 WScreen *scr = wwin->screen_ptr;
504 int i;
59eb9475 dan1998-11-03 12:53:26 +0000505
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200506 updateOptionsMenu(menu, wwin);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000507
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200508 updateMakeShortcutMenu(menu, wwin);
6830b057 dan2004-10-12 21:28:27 +0000509
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200510 wMenuSetEnabled(menu, MC_HIDE, wapp != NULL && !WFLAGP(wapp->main_window_desc, no_appicon));
0261c326 dan1999-01-06 15:22:33 +0000511
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200512 wMenuSetEnabled(menu, MC_CLOSE, (wwin->protocols.DELETE_WINDOW && !WFLAGP(wwin, no_closable)));
0261c326 dan1999-01-06 15:22:33 +0000513
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200514 if (wwin->flags.miniaturized) {
515 static char *text = NULL;
516 if (!text)
517 text = _("Deminiaturize");
0261c326 dan1999-01-06 15:22:33 +0000518
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200519 menu->entries[MC_MINIATURIZE]->text = text;
520 } else {
521 static char *text = NULL;
522 if (!text)
523 text = _("Miniaturize");
0261c326 dan1999-01-06 15:22:33 +0000524
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200525 menu->entries[MC_MINIATURIZE]->text = text;
526 }
0261c326 dan1999-01-06 15:22:33 +0000527
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200528 wMenuSetEnabled(menu, MC_MINIATURIZE, !WFLAGP(wwin, no_miniaturizable));
0261c326 dan1999-01-06 15:22:33 +0000529
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200530 if (wwin->flags.maximized) {
531 static char *text = NULL;
532 if (!text)
533 text = _("Unmaximize");
0261c326 dan1999-01-06 15:22:33 +0000534
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200535 menu->entries[MC_MAXIMIZE]->text = text;
536 } else {
537 static char *text = NULL;
538 if (!text)
539 text = _("Maximize");
e7495baf dan1999-02-17 11:06:40 +0000540
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200541 menu->entries[MC_MAXIMIZE]->text = text;
542 }
543 wMenuSetEnabled(menu, MC_MAXIMIZE, IS_RESIZABLE(wwin));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000544
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200545 wMenuSetEnabled(menu, MC_MOVERESIZE, IS_RESIZABLE(wwin)
546 && !wwin->flags.miniaturized);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000547
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200548 if (wwin->flags.shaded) {
549 static char *text = NULL;
550 if (!text)
551 text = _("Unshade");
0261c326 dan1999-01-06 15:22:33 +0000552
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200553 menu->entries[MC_SHADE]->text = text;
554 } else {
555 static char *text = NULL;
556 if (!text)
557 text = _("Shade");
0261c326 dan1999-01-06 15:22:33 +0000558
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200559 menu->entries[MC_SHADE]->text = text;
560 }
0261c326 dan1999-01-06 15:22:33 +0000561
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200562 wMenuSetEnabled(menu, MC_SHADE, !WFLAGP(wwin, no_shadeable)
563 && !wwin->flags.miniaturized);
0261c326 dan1999-01-06 15:22:33 +0000564
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200565 wMenuSetEnabled(menu, MC_DUMMY_MOVETO, !IS_OMNIPRESENT(wwin));
6830b057 dan2004-10-12 21:28:27 +0000566
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200567 if (!wwin->flags.inspector_open) {
568 wMenuSetEnabled(menu, MC_PROPERTIES, True);
569 } else {
570 wMenuSetEnabled(menu, MC_PROPERTIES, False);
571 }
6830b057 dan2004-10-12 21:28:27 +0000572
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200573 /* set the client data of the entries to the window */
574 for (i = 0; i < menu->entry_no; i++) {
575 menu->entries[i]->clientdata = wwin;
576 }
59eb9475 dan1998-11-03 12:53:26 +0000577
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200578 for (i = 0; i < scr->workspace_submenu->entry_no; i++) {
579 scr->workspace_submenu->entries[i]->clientdata = wwin;
580 if (i == scr->current_workspace) {
581 wMenuSetEnabled(scr->workspace_submenu, i, False);
582 } else {
583 wMenuSetEnabled(scr->workspace_submenu, i, True);
584 }
585 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000586
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200587 menu->flags.realized = 0;
588 wMenuRealize(menu);
0261c326 dan1999-01-06 15:22:33 +0000589}
590
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200591void OpenWindowMenu(WWindow * wwin, int x, int y, int keyboard)
0261c326 dan1999-01-06 15:22:33 +0000592{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200593 WMenu *menu;
594 WScreen *scr = wwin->screen_ptr;
595
596 wwin->flags.menu_open_for_me = 1;
597
598 if (!scr->window_menu) {
599 scr->window_menu = createWindowMenu(scr);
600
601 /* hack to save some memory allocation/deallocation */
602 wfree(scr->window_menu->entries[MC_MINIATURIZE]->text);
603 wfree(scr->window_menu->entries[MC_MAXIMIZE]->text);
604 wfree(scr->window_menu->entries[MC_SHADE]->text);
605 } else {
606 updateWorkspaceMenu(scr->workspace_submenu);
607 }
608
609 menu = scr->window_menu;
610 if (menu->flags.mapped) {
611 wMenuUnmap(menu);
612 if (menu->entries[0]->clientdata == wwin) {
613 return;
614 }
615 }
616
617 updateMenuForWindow(menu, wwin);
618
619 x -= menu->frame->core->width / 2;
620 if (x + menu->frame->core->width > wwin->frame_x + wwin->frame->core->width)
621 x = wwin->frame_x + wwin->frame->core->width - menu->frame->core->width;
622 if (x < wwin->frame_x)
623 x = wwin->frame_x;
624
625 if (!wwin->flags.internal_window)
626 wMenuMapAt(menu, x, y, keyboard);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000627}
0261c326 dan1999-01-06 15:22:33 +0000628
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200629void OpenMiniwindowMenu(WWindow * wwin, int x, int y)
0261c326 dan1999-01-06 15:22:33 +0000630{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200631 WMenu *menu;
632 WScreen *scr = wwin->screen_ptr;
0261c326 dan1999-01-06 15:22:33 +0000633
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200634 wwin->flags.menu_open_for_me = 1;
0261c326 dan1999-01-06 15:22:33 +0000635
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200636 if (!scr->window_menu) {
637 scr->window_menu = createWindowMenu(scr);
6830b057 dan2004-10-12 21:28:27 +0000638
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200639 /* hack to save some memory allocation/deallocation */
640 wfree(scr->window_menu->entries[MC_MINIATURIZE]->text);
641 wfree(scr->window_menu->entries[MC_MAXIMIZE]->text);
642 wfree(scr->window_menu->entries[MC_SHADE]->text);
643 } else {
644 updateWorkspaceMenu(scr->workspace_submenu);
645 }
0261c326 dan1999-01-06 15:22:33 +0000646
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200647 menu = scr->window_menu;
648 if (menu->flags.mapped) {
649 wMenuUnmap(menu);
650 if (menu->entries[0]->clientdata == wwin) {
651 return;
652 }
653 }
0261c326 dan1999-01-06 15:22:33 +0000654
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200655 updateMenuForWindow(menu, wwin);
6830b057 dan2004-10-12 21:28:27 +0000656
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200657 x -= menu->frame->core->width / 2;
0261c326 dan1999-01-06 15:22:33 +0000658
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200659 wMenuMapAt(menu, x, y, False);
0261c326 dan1999-01-06 15:22:33 +0000660}