Update other window menu shortcut labels.
[wmaker-crm.git] / src / winmenu.c
blob5d56759f71b2a1cbc045650451c50be5e318af81
1 /* winmenu.c - command menu for windows
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
7 * 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.
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.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "wconfig.h"
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <unistd.h>
27 #include <string.h>
29 #include <X11/Xlib.h>
30 #include <X11/Xutil.h>
31 #include <X11/XKBlib.h>
33 #include "WindowMaker.h"
34 #include "actions.h"
35 #include "menu.h"
36 #include "main.h"
37 #include "window.h"
38 #include "client.h"
39 #include "application.h"
40 #include "keybind.h"
41 #include "misc.h"
42 #include "framewin.h"
43 #include "workspace.h"
44 #include "winspector.h"
45 #include "dialog.h"
46 #include "stacking.h"
47 #include "icon.h"
48 #include "xinerama.h"
49 #include "winmenu.h"
51 enum
53 MC_MAXIMIZE,
54 MC_OTHERMAX,
55 MC_MINIATURIZE,
56 MC_SHADE,
57 MC_HIDE,
58 MC_MOVERESIZE,
59 MC_SELECT,
60 MC_DUMMY_MOVETO,
61 MC_PROPERTIES,
62 MC_OPTIONS,
63 MC_RELAUNCH,
64 MC_CLOSE,
65 MC_KILL
68 enum
70 WO_KEEP_ON_TOP,
71 WO_KEEP_AT_BOTTOM,
72 WO_OMNIPRESENT,
73 WO_ENTRIES
76 enum
78 MAXC_V,
79 MAXC_H,
80 MAXC_LH,
81 MAXC_RH,
82 MAXC_TH,
83 MAXC_BH,
84 MAXC_LTC,
85 MAXC_RTC,
86 MAXC_LBC,
87 MAXC_RBC,
88 MAXC_MAXIMUS
91 static void updateOptionsMenu(WMenu * menu, WWindow * wwin);
93 static void execWindowOptionCommand(WMenu * menu, WMenuEntry * entry)
95 WWindow *wwin = (WWindow *) entry->clientdata;
97 /* Parameter not used, but tell the compiler that it is ok */
98 (void) menu;
100 switch (entry->order) {
101 case WO_KEEP_ON_TOP:
102 if (wwin->frame->core->stacking->window_level != WMFloatingLevel)
103 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
104 else
105 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
106 break;
108 case WO_KEEP_AT_BOTTOM:
109 if (wwin->frame->core->stacking->window_level != WMSunkenLevel)
110 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
111 else
112 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
113 break;
115 case WO_OMNIPRESENT:
116 wWindowSetOmnipresent(wwin, !wwin->flags.omnipresent);
117 break;
121 static void execMaximizeCommand(WMenu * menu, WMenuEntry * entry)
123 WWindow *wwin = (WWindow *) entry->clientdata;
125 (void) menu;
128 switch (entry->order) {
129 case MAXC_V:
130 handleMaximize(wwin, MAX_VERTICAL);
131 break;
133 case MAXC_H:
134 handleMaximize(wwin,MAX_HORIZONTAL);
135 break;
137 case MAXC_LH:
138 handleMaximize(wwin,MAX_VERTICAL | MAX_LEFTHALF);
139 break;
141 case MAXC_RH:
142 handleMaximize(wwin,MAX_VERTICAL | MAX_RIGHTHALF);
143 break;
145 case MAXC_TH:
146 handleMaximize(wwin,MAX_HORIZONTAL | MAX_TOPHALF);
147 break;
149 case MAXC_BH:
150 handleMaximize(wwin,MAX_HORIZONTAL | MAX_BOTTOMHALF);
151 break;
153 case MAXC_LTC:
154 handleMaximize(wwin,MAX_LEFTHALF | MAX_TOPHALF);
155 break;
157 case MAXC_RTC:
158 handleMaximize(wwin,MAX_RIGHTHALF | MAX_TOPHALF);
159 break;
161 case MAXC_LBC:
162 handleMaximize(wwin,MAX_LEFTHALF | MAX_BOTTOMHALF);
163 break;
165 case MAXC_RBC:
166 handleMaximize(wwin,MAX_RIGHTHALF | MAX_BOTTOMHALF);
167 break;
169 case MAXC_MAXIMUS:
170 handleMaximize(wwin,MAX_MAXIMUS);
171 break;
176 static void updateUnmaximizeShortcut(WMenuEntry * entry, int flags)
178 int key;
180 switch (flags & (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_TOPHALF | MAX_BOTTOMHALF | MAX_MAXIMUS)) {
181 case MAX_HORIZONTAL:
182 key = WKBD_HMAXIMIZE;
183 break;
185 case MAX_VERTICAL:
186 key = WKBD_VMAXIMIZE;
187 break;
189 case MAX_LEFTHALF | MAX_VERTICAL:
190 key = WKBD_LHMAXIMIZE;
191 break;
193 case MAX_RIGHTHALF | MAX_VERTICAL:
194 key = WKBD_RHMAXIMIZE;
195 break;
197 case MAX_TOPHALF | MAX_HORIZONTAL:
198 key = WKBD_THMAXIMIZE;
199 break;
201 case MAX_BOTTOMHALF | MAX_HORIZONTAL:
202 key = WKBD_BHMAXIMIZE;
203 break;
205 case MAX_LEFTHALF | MAX_TOPHALF:
206 key = WKBD_LTCMAXIMIZE;
207 break;
209 case MAX_RIGHTHALF | MAX_TOPHALF:
210 key = WKBD_RTCMAXIMIZE;
211 break;
213 case MAX_LEFTHALF | MAX_BOTTOMHALF:
214 key = WKBD_LBCMAXIMIZE;
215 break;
217 case MAX_RIGHTHALF | MAX_BOTTOMHALF:
218 key = WKBD_RBCMAXIMIZE;
219 break;
221 case MAX_MAXIMUS:
222 key = WKBD_MAXIMUS;
223 break;
225 default:
226 key = WKBD_MAXIMIZE;
227 break;
230 entry->rtext = GetShortcutKey(wKeyBindings[key]);
233 static void execMenuCommand(WMenu * menu, WMenuEntry * entry)
235 WWindow *wwin = (WWindow *) entry->clientdata;
236 WApplication *wapp;
238 CloseWindowMenu(menu->frame->screen_ptr);
240 switch (entry->order) {
241 case MC_CLOSE:
242 /* send delete message */
243 wClientSendProtocol(wwin, w_global.atom.wm.delete_window,
244 w_global.timestamp.last_event);
245 break;
247 case MC_KILL:
248 wretain(wwin);
249 if (wPreferences.dont_confirm_kill
250 || wMessageDialog(menu->frame->screen_ptr, _("Kill Application"),
252 ("This will kill the application.\nAny unsaved changes will be lost.\nPlease confirm."),
253 _("Yes"), _("No"), NULL) == WAPRDefault) {
254 if (!wwin->flags.destroyed)
255 wClientKill(wwin);
257 wrelease(wwin);
258 break;
260 case MC_MINIATURIZE:
261 if (wwin->flags.miniaturized) {
262 wDeiconifyWindow(wwin);
263 } else {
264 if (wwin->protocols.MINIATURIZE_WINDOW) {
265 wClientSendProtocol(wwin, w_global.atom.gnustep.wm_miniaturize_window,
266 w_global.timestamp.last_event);
267 } else {
268 wIconifyWindow(wwin);
271 break;
273 case MC_MAXIMIZE:
274 if (wwin->flags.maximized)
275 wUnmaximizeWindow(wwin);
276 else
277 wMaximizeWindow(wwin, MAX_VERTICAL | MAX_HORIZONTAL);
278 break;
280 case MC_SHADE:
281 if (wwin->flags.shaded)
282 wUnshadeWindow(wwin);
283 else
284 wShadeWindow(wwin);
285 break;
287 case MC_SELECT:
288 if (!wwin->flags.miniaturized)
289 wSelectWindow(wwin, !wwin->flags.selected);
290 else
291 wIconSelect(wwin->icon);
292 break;
294 case MC_MOVERESIZE:
295 wKeyboardMoveResizeWindow(wwin);
296 break;
298 case MC_PROPERTIES:
299 wShowInspectorForWindow(wwin);
300 break;
302 case MC_RELAUNCH:
303 (void) RelaunchWindow(wwin);
304 break;
306 case MC_HIDE:
307 wapp = wApplicationOf(wwin->main_window);
308 wHideApplication(wapp);
309 break;
313 static void switchWSCommand(WMenu * menu, WMenuEntry * entry)
315 WWindow *wwin = (WWindow *) entry->clientdata;
317 /* Parameter not used, but tell the compiler that it is ok */
318 (void) menu;
320 wSelectWindow(wwin, False);
321 wWindowChangeWorkspace(wwin, entry->order);
324 static void makeShortcutCommand(WMenu *menu, WMenuEntry *entry)
326 WWindow *wwin = (WWindow *) entry->clientdata;
327 WScreen *scr = wwin->screen_ptr;
328 int index = entry->order - WO_ENTRIES;
330 /* Parameter not used, but tell the compiler that it is ok */
331 (void) menu;
333 if (w_global.shortcut.windows[index]) {
334 WMFreeArray(w_global.shortcut.windows[index]);
335 w_global.shortcut.windows[index] = NULL;
338 if (wwin->flags.selected && scr->selected_windows) {
339 w_global.shortcut.windows[index] = WMDuplicateArray(scr->selected_windows);
340 } else {
341 w_global.shortcut.windows[index] = WMCreateArray(4);
342 WMAddToArray(w_global.shortcut.windows[index], wwin);
345 wSelectWindow(wwin, !wwin->flags.selected);
346 XFlush(dpy);
347 wusleep(3000);
348 wSelectWindow(wwin, !wwin->flags.selected);
349 XFlush(dpy);
352 static void updateWorkspaceMenu(WMenu * menu)
354 char title[MAX_WORKSPACENAME_WIDTH + 1];
355 WMenuEntry *entry;
356 int i;
358 for (i = 0; i < w_global.workspace.count; i++) {
359 if (i < menu->entry_no) {
361 entry = menu->entries[i];
362 if (strcmp(entry->text, w_global.workspace.array[i]->name) != 0) {
363 wfree(entry->text);
364 strncpy(title, w_global.workspace.array[i]->name, MAX_WORKSPACENAME_WIDTH);
365 title[MAX_WORKSPACENAME_WIDTH] = 0;
366 menu->entries[i]->text = wstrdup(title);
367 menu->entries[i]->rtext = GetShortcutKey(wKeyBindings[WKBD_MOVE_WORKSPACE1 + i]);
368 menu->flags.realized = 0;
370 } else {
371 strncpy(title, w_global.workspace.array[i]->name, MAX_WORKSPACENAME_WIDTH);
372 title[MAX_WORKSPACENAME_WIDTH] = 0;
374 entry = wMenuAddCallback(menu, title, switchWSCommand, NULL);
375 entry->rtext = GetShortcutKey(wKeyBindings[WKBD_MOVE_WORKSPACE1 + i]);
377 menu->flags.realized = 0;
380 /* workspace shortcut labels */
381 if (i / 10 == w_global.workspace.current / 10)
382 entry->rtext = GetShortcutKey(wKeyBindings[WKBD_MOVE_WORKSPACE1 + (i % 10)]);
383 else
384 entry->rtext = NULL;
387 if (!menu->flags.realized)
388 wMenuRealize(menu);
391 static void updateMakeShortcutMenu(WMenu *menu, WWindow *wwin)
393 WMenu *smenu = menu->cascades[menu->entries[MC_OPTIONS]->cascade];
394 int i;
395 char *buffer;
396 int buflen;
397 KeyCode kcode;
399 if (!smenu)
400 return;
402 buflen = strlen(_("Set Shortcut")) + 16;
403 buffer = wmalloc(buflen);
405 for (i = WO_ENTRIES; i < smenu->entry_no; i++) {
406 char *tmp;
407 int shortcutNo = i - WO_ENTRIES;
408 WMenuEntry *entry = smenu->entries[i];
409 WMArray *shortSelWindows = w_global.shortcut.windows[shortcutNo];
411 snprintf(buffer, buflen, "%s %i", _("Set Shortcut"), shortcutNo + 1);
413 if (!shortSelWindows) {
414 entry->flags.indicator_on = 0;
415 } else {
416 entry->flags.indicator_on = 1;
417 if (WMCountInArray(shortSelWindows, wwin))
418 entry->flags.indicator_type = MI_DIAMOND;
419 else
420 entry->flags.indicator_type = MI_CHECK;
423 if (strcmp(buffer, entry->text) != 0) {
424 wfree(entry->text);
425 entry->text = wstrdup(buffer);
426 smenu->flags.realized = 0;
429 kcode = wKeyBindings[WKBD_WINDOW1 + shortcutNo].keycode;
431 if (kcode) {
432 if ((tmp = GetShortcutKey(wKeyBindings[WKBD_WINDOW1 + shortcutNo]))
433 && (!entry->rtext || strcmp(tmp, entry->rtext) != 0)) {
434 if (entry->rtext)
435 wfree(entry->rtext);
436 entry->rtext = tmp;
437 smenu->flags.realized = 0;
439 wMenuSetEnabled(smenu, i, True);
440 } else {
441 wMenuSetEnabled(smenu, i, False);
442 if (entry->rtext) {
443 wfree(entry->rtext);
444 entry->rtext = NULL;
445 smenu->flags.realized = 0;
448 entry->clientdata = wwin;
450 wfree(buffer);
451 if (!smenu->flags.realized)
452 wMenuRealize(smenu);
455 static void updateOptionsMenu(WMenu * menu, WWindow * wwin)
457 WMenu *smenu = menu->cascades[menu->entries[MC_OPTIONS]->cascade];
459 /* keep on top check */
460 smenu->entries[WO_KEEP_ON_TOP]->clientdata = wwin;
461 smenu->entries[WO_KEEP_ON_TOP]->flags.indicator_on =
462 (wwin->frame->core->stacking->window_level == WMFloatingLevel) ? 1 : 0;
463 wMenuSetEnabled(smenu, WO_KEEP_ON_TOP, !wwin->flags.miniaturized);
465 /* keep at bottom check */
466 smenu->entries[WO_KEEP_AT_BOTTOM]->clientdata = wwin;
467 smenu->entries[WO_KEEP_AT_BOTTOM]->flags.indicator_on =
468 (wwin->frame->core->stacking->window_level == WMSunkenLevel) ? 1 : 0;
469 wMenuSetEnabled(smenu, WO_KEEP_AT_BOTTOM, !wwin->flags.miniaturized);
471 /* omnipresent check */
472 smenu->entries[WO_OMNIPRESENT]->clientdata = wwin;
473 smenu->entries[WO_OMNIPRESENT]->flags.indicator_on = IS_OMNIPRESENT(wwin);
475 smenu->flags.realized = 0;
476 wMenuRealize(smenu);
479 static void updateMaximizeMenu(WMenu * menu, WWindow * wwin)
481 WMenu *smenu = menu->cascades[menu->entries[MC_OTHERMAX]->cascade];
483 smenu->entries[MAXC_V]->clientdata = wwin;
484 smenu->entries[MAXC_V]->rtext = GetShortcutKey(wKeyBindings[WKBD_VMAXIMIZE]);
486 smenu->entries[MAXC_H]->clientdata = wwin;
487 smenu->entries[MAXC_H]->rtext = GetShortcutKey(wKeyBindings[WKBD_HMAXIMIZE]);
489 smenu->entries[MAXC_LH]->clientdata = wwin;
490 smenu->entries[MAXC_LH]->rtext = GetShortcutKey(wKeyBindings[WKBD_LHMAXIMIZE]);
492 smenu->entries[MAXC_RH]->clientdata = wwin;
493 smenu->entries[MAXC_RH]->rtext = GetShortcutKey(wKeyBindings[WKBD_RHMAXIMIZE]);
495 smenu->entries[MAXC_TH]->clientdata = wwin;
496 smenu->entries[MAXC_TH]->rtext = GetShortcutKey(wKeyBindings[WKBD_THMAXIMIZE]);
498 smenu->entries[MAXC_BH]->clientdata = wwin;
499 smenu->entries[MAXC_BH]->rtext = GetShortcutKey(wKeyBindings[WKBD_BHMAXIMIZE]);
501 smenu->entries[MAXC_LTC]->clientdata = wwin;
502 smenu->entries[MAXC_LTC]->rtext = GetShortcutKey(wKeyBindings[WKBD_LTCMAXIMIZE]);
504 smenu->entries[MAXC_RTC]->clientdata = wwin;
505 smenu->entries[MAXC_RTC]->rtext = GetShortcutKey(wKeyBindings[WKBD_RTCMAXIMIZE]);
507 smenu->entries[MAXC_LBC]->clientdata = wwin;
508 smenu->entries[MAXC_LBC]->rtext = GetShortcutKey(wKeyBindings[WKBD_LBCMAXIMIZE]);
510 smenu->entries[MAXC_RBC]->clientdata = wwin;
511 smenu->entries[MAXC_RBC]->rtext = GetShortcutKey(wKeyBindings[WKBD_RBCMAXIMIZE]);
513 smenu->entries[MAXC_MAXIMUS]->clientdata = wwin;
514 smenu->entries[MAXC_MAXIMUS]->rtext = GetShortcutKey(wKeyBindings[WKBD_MAXIMUS]);
516 smenu->flags.realized = 0;
517 wMenuRealize(smenu);
520 static WMenu *makeWorkspaceMenu(WScreen * scr)
522 WMenu *menu;
524 menu = wMenuCreate(scr, NULL, False);
525 if (!menu) {
526 wwarning(_("could not create submenu for window menu"));
527 return NULL;
530 updateWorkspaceMenu(menu);
532 return menu;
535 static WMenu *makeMakeShortcutMenu(WMenu *menu)
537 int i;
539 for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
540 WMenuEntry *entry;
541 entry = wMenuAddCallback(menu, "", makeShortcutCommand, NULL);
543 entry->flags.indicator = 1;
546 return menu;
549 static WMenu *makeOptionsMenu(WScreen * scr)
551 WMenu *menu;
552 WMenuEntry *entry;
554 menu = wMenuCreate(scr, NULL, False);
555 if (!menu) {
556 wwarning(_("could not create submenu for window menu"));
557 return NULL;
560 entry = wMenuAddCallback(menu, _("Keep on top"), execWindowOptionCommand, NULL);
561 entry->flags.indicator = 1;
562 entry->flags.indicator_type = MI_CHECK;
564 entry = wMenuAddCallback(menu, _("Keep at bottom"), execWindowOptionCommand, NULL);
565 entry->flags.indicator = 1;
566 entry->flags.indicator_type = MI_CHECK;
568 entry = wMenuAddCallback(menu, _("Omnipresent"), execWindowOptionCommand, NULL);
569 entry->flags.indicator = 1;
570 entry->flags.indicator_type = MI_CHECK;
572 return menu;
575 static WMenu *makeMaximizeMenu(WScreen * scr)
577 WMenu *menu;
578 WMenuEntry *entry;
580 menu = wMenuCreate(scr, NULL, False);
581 if (!menu) {
582 wwarning(_("could not create submenu for window menu"));
583 return NULL;
586 entry = wMenuAddCallback(menu, _("Maximize vertically"), execMaximizeCommand, NULL);
587 entry = wMenuAddCallback(menu, _("Maximize horizontally"), execMaximizeCommand, NULL);
588 entry = wMenuAddCallback(menu, _("Maximize left half"), execMaximizeCommand, NULL);
589 entry = wMenuAddCallback(menu, _("Maximize right half"), execMaximizeCommand, NULL);
590 entry = wMenuAddCallback(menu, _("Maximize top half"), execMaximizeCommand, NULL);
591 entry = wMenuAddCallback(menu, _("Maximize bottom half"), execMaximizeCommand, NULL);
592 entry = wMenuAddCallback(menu, _("Maximize left top corner"), execMaximizeCommand, NULL);
593 entry = wMenuAddCallback(menu, _("Maximize right top corner"), execMaximizeCommand, NULL);
594 entry = wMenuAddCallback(menu, _("Maximize left bottom corner"), execMaximizeCommand, NULL);
595 entry = wMenuAddCallback(menu, _("Maximize right bottom corner"), execMaximizeCommand, NULL);
596 entry = wMenuAddCallback(menu, _("Maximus: tiled maximization"), execMaximizeCommand, NULL);
598 return menu;
601 static WMenu *createWindowMenu(WScreen * scr)
603 WMenu *menu;
604 WMenuEntry *entry;
606 menu = wMenuCreate(scr, NULL, False);
608 * Warning: If you make some change that affects the order of the
609 * entries, you must update the command enum in the top of
610 * this file.
612 entry = wMenuAddCallback(menu, _("Maximize"), execMenuCommand, NULL);
614 entry = wMenuAddCallback(menu, _("Other maximization"), NULL, NULL);
615 wMenuEntrySetCascade(menu, entry, makeMaximizeMenu(scr));
617 entry = wMenuAddCallback(menu, _("Miniaturize"), execMenuCommand, NULL);
619 entry = wMenuAddCallback(menu, _("Shade"), execMenuCommand, NULL);
621 entry = wMenuAddCallback(menu, _("Hide"), execMenuCommand, NULL);
623 entry = wMenuAddCallback(menu, _("Resize/Move"), execMenuCommand, NULL);
625 entry = wMenuAddCallback(menu, _("Select"), execMenuCommand, NULL);
627 entry = wMenuAddCallback(menu, _("Move To"), NULL, NULL);
628 w_global.workspace.submenu = makeWorkspaceMenu(scr);
629 if (w_global.workspace.submenu)
630 wMenuEntrySetCascade(menu, entry, w_global.workspace.submenu);
632 entry = wMenuAddCallback(menu, _("Attributes..."), execMenuCommand, NULL);
634 entry = wMenuAddCallback(menu, _("Options"), NULL, NULL);
635 wMenuEntrySetCascade(menu, entry, makeMakeShortcutMenu(makeOptionsMenu(scr)));
637 entry = wMenuAddCallback(menu, _("Launch"), execMenuCommand, NULL);
639 entry = wMenuAddCallback(menu, _("Close"), execMenuCommand, NULL);
641 entry = wMenuAddCallback(menu, _("Kill"), execMenuCommand, NULL);
643 return menu;
646 void CloseWindowMenu(WScreen * scr)
648 if (scr->window_menu) {
649 if (scr->window_menu->flags.mapped)
650 wMenuUnmap(scr->window_menu);
652 if (scr->window_menu->entries[0]->clientdata) {
653 WWindow *wwin = (WWindow *) scr->window_menu->entries[0]->clientdata;
655 wwin->flags.menu_open_for_me = 0;
657 scr->window_menu->entries[0]->clientdata = NULL;
661 static void updateMenuForWindow(WMenu * menu, WWindow * wwin)
663 WApplication *wapp = wApplicationOf(wwin->main_window);
664 int i;
666 updateOptionsMenu(menu, wwin);
667 updateMaximizeMenu(menu, wwin);
669 updateMakeShortcutMenu(menu, wwin);
671 wMenuSetEnabled(menu, MC_HIDE, wapp != NULL && !WFLAGP(wapp->main_window_desc, no_appicon));
673 wMenuSetEnabled(menu, MC_CLOSE, (wwin->protocols.DELETE_WINDOW && !WFLAGP(wwin, no_closable)));
675 if (wwin->flags.miniaturized) {
676 static char *text = NULL;
677 if (!text)
678 text = _("Deminiaturize");
680 menu->entries[MC_MINIATURIZE]->text = text;
681 } else {
682 static char *text = NULL;
683 if (!text)
684 text = _("Miniaturize");
686 menu->entries[MC_MINIATURIZE]->text = text;
689 wMenuSetEnabled(menu, MC_MINIATURIZE, !WFLAGP(wwin, no_miniaturizable));
691 if (wwin->flags.maximized) {
692 static char *text = NULL;
693 if (!text)
694 text = _("Unmaximize");
696 menu->entries[MC_MAXIMIZE]->text = text;
697 updateUnmaximizeShortcut(menu->entries[MC_MAXIMIZE], wwin->flags.maximized);
698 } else {
699 static char *text = NULL;
700 if (!text)
701 text = _("Maximize");
703 menu->entries[MC_MAXIMIZE]->text = text;
704 menu->entries[MC_MAXIMIZE]->rtext = GetShortcutKey(wKeyBindings[WKBD_MAXIMIZE]);
706 wMenuSetEnabled(menu, MC_MAXIMIZE, IS_RESIZABLE(wwin));
708 wMenuSetEnabled(menu, MC_MOVERESIZE, IS_RESIZABLE(wwin)
709 && !wwin->flags.miniaturized);
711 if (wwin->flags.shaded) {
712 static char *text = NULL;
713 if (!text)
714 text = _("Unshade");
716 menu->entries[MC_SHADE]->text = text;
717 } else {
718 static char *text = NULL;
719 if (!text)
720 text = _("Shade");
722 menu->entries[MC_SHADE]->text = text;
725 wMenuSetEnabled(menu, MC_SHADE, !WFLAGP(wwin, no_shadeable)
726 && !wwin->flags.miniaturized);
728 if (wwin->flags.selected) {
729 static char *text = NULL;
730 if (!text)
731 text = _("Deselect");
733 menu->entries[MC_SELECT]->text = text;
734 } else {
735 static char *text = NULL;
736 if (!text)
737 text = _("Select");
739 menu->entries[MC_SELECT]->text = text;
742 wMenuSetEnabled(menu, MC_DUMMY_MOVETO, !IS_OMNIPRESENT(wwin));
744 if (!wwin->flags.inspector_open) {
745 wMenuSetEnabled(menu, MC_PROPERTIES, True);
746 } else {
747 wMenuSetEnabled(menu, MC_PROPERTIES, False);
750 /* Update shortcut labels except for (Un)Maximize which is
751 * handled separately.
753 menu->entries[MC_MINIATURIZE]->rtext = GetShortcutKey(wKeyBindings[WKBD_MINIATURIZE]);
754 menu->entries[MC_SHADE]->rtext = GetShortcutKey(wKeyBindings[WKBD_SHADE]);
755 menu->entries[MC_HIDE]->rtext = GetShortcutKey(wKeyBindings[WKBD_HIDE]);
756 menu->entries[MC_MOVERESIZE]->rtext = GetShortcutKey(wKeyBindings[WKBD_MOVERESIZE]);
757 menu->entries[MC_SELECT]->rtext = GetShortcutKey(wKeyBindings[WKBD_SELECT]);
758 menu->entries[MC_RELAUNCH]->rtext = GetShortcutKey(wKeyBindings[WKBD_RELAUNCH]);
759 menu->entries[MC_CLOSE]->rtext = GetShortcutKey(wKeyBindings[WKBD_CLOSE]);
761 /* set the client data of the entries to the window */
762 for (i = 0; i < menu->entry_no; i++) {
763 menu->entries[i]->clientdata = wwin;
766 for (i = 0; i < w_global.workspace.submenu->entry_no; i++) {
767 w_global.workspace.submenu->entries[i]->clientdata = wwin;
769 if (i == w_global.workspace.current)
770 wMenuSetEnabled(w_global.workspace.submenu, i, False);
771 else
772 wMenuSetEnabled(w_global.workspace.submenu, i, True);
775 menu->flags.realized = 0;
776 wMenuRealize(menu);
779 static WMenu *open_window_menu_core(WWindow *wwin)
781 WScreen *scr = wwin->screen_ptr;
782 WMenu *menu;
784 wwin->flags.menu_open_for_me = 1;
786 if (!scr->window_menu) {
787 scr->window_menu = createWindowMenu(scr);
789 /* hack to save some memory allocation/deallocation */
790 wfree(scr->window_menu->entries[MC_MINIATURIZE]->text);
791 wfree(scr->window_menu->entries[MC_MAXIMIZE]->text);
792 wfree(scr->window_menu->entries[MC_SHADE]->text);
793 wfree(scr->window_menu->entries[MC_SELECT]->text);
794 } else {
795 updateWorkspaceMenu(w_global.workspace.submenu);
798 menu = scr->window_menu;
799 if (menu->flags.mapped) {
800 wMenuUnmap(menu);
801 if (menu->entries[0]->clientdata == wwin)
802 return NULL;
805 updateMenuForWindow(menu, wwin);
807 return menu;
810 static void prepare_menu_position(WMenu *menu, int x, int y)
812 WMRect rect;
814 rect = wGetRectForHead(menu->frame->screen_ptr,
815 wGetHeadForPointerLocation(menu->frame->screen_ptr));
816 if (x < rect.pos.x - menu->frame->core->width / 2)
817 x = rect.pos.x - menu->frame->core->width / 2;
818 if (y < rect.pos.y)
819 y = rect.pos.y;
822 void OpenWindowMenu(WWindow *wwin, int x, int y, int keyboard)
824 WMenu *menu;
826 menu = open_window_menu_core(wwin);
827 if (!menu)
828 return;
830 /* Specific menu position */
831 x -= menu->frame->core->width / 2;
832 if (x + menu->frame->core->width > wwin->frame_x + wwin->frame->core->width)
833 x = wwin->frame_x + wwin->frame->core->width - menu->frame->core->width;
834 if (x < wwin->frame_x)
835 x = wwin->frame_x;
837 /* Common menu position */
838 prepare_menu_position(menu, x, y);
840 if (!wwin->flags.internal_window)
841 wMenuMapAt(menu, x, y, keyboard);
844 void OpenWindowMenu2(WWindow *wwin, int x, int y, int keyboard)
846 int i;
847 WMenu *menu;
849 menu = open_window_menu_core(wwin);
850 if (!menu)
851 return;
853 /* Specific menu position */
854 for (i = 0; i < w_global.workspace.submenu->entry_no; i++) {
855 w_global.workspace.submenu->entries[i]->clientdata = wwin;
856 wMenuSetEnabled(w_global.workspace.submenu, i, True);
859 x -= menu->frame->core->width / 2;
861 /* Common menu position */
862 prepare_menu_position(menu, x, y);
864 if (!wwin->flags.internal_window)
865 wMenuMapAt(menu, x, y, keyboard);
868 void OpenMiniwindowMenu(WWindow * wwin, int x, int y)
870 WMenu *menu;
872 menu = open_window_menu_core(wwin);
873 if (!menu)
874 return;
876 x -= menu->frame->core->width / 2;
878 wMenuMapAt(menu, x, y, False);
881 void DestroyWindowMenu(WScreen *scr)
883 if (scr->window_menu) {
884 scr->window_menu->entries[MC_MINIATURIZE]->text = NULL;
885 scr->window_menu->entries[MC_MAXIMIZE]->text = NULL;
886 scr->window_menu->entries[MC_SHADE]->text = NULL;
887 scr->window_menu->entries[MC_SELECT]->text = NULL;
888 wMenuDestroy(scr->window_menu, True);
889 scr->window_menu = NULL;