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.
30 #include <X11/Xutil.h>
31 #include <X11/XKBlib.h>
33 #include "WindowMaker.h"
39 #include "application.h"
43 #include "workspace.h"
44 #include "winspector.h"
52 static WMenu
*makeWorkspaceMenu(WScreen
*scr
);
53 static WMenu
*makeOptionsMenu(WScreen
*scr
);
54 static WMenu
*makeMaximizeMenu(WScreen
*scr
);
57 * Define the Menu entry that will be present in the Window menu
59 * The order of this list defines the order in which they will appear;
60 * make sure to keep the structure below aligned with the list because
61 * the constant index is used in many places.
82 WMenu
*(*generate_submenu
)(WScreen
*scr
);
83 } window_menu_entries
[] = {
84 [MC_MAXIMIZE
] = { N_("Maximize"), NULL
},
85 [MC_OTHERMAX
] = { N_("Other maximization"), makeMaximizeMenu
},
86 [MC_MINIATURIZE
] = { N_("Miniaturize"), NULL
},
87 [MC_SHADE
] = { N_("Shade"), NULL
},
88 [MC_HIDE
] = { N_("Hide"), NULL
},
89 [MC_MOVERESIZE
] = { N_("Resize/Move"), NULL
},
90 [MC_SELECT
] = { N_("Select"), NULL
},
91 [MC_CHANGEWKSPC
] = { N_("Move To"), makeWorkspaceMenu
},
92 [MC_PROPERTIES
] = { N_("Attributes..."), NULL
},
93 [MC_OPTIONS
] = { N_("Options"), makeOptionsMenu
},
94 [MC_RELAUNCH
] = { N_("Launch"), NULL
},
95 [MC_CLOSE
] = { N_("Close"), NULL
},
96 [MC_KILL
] = { N_("Kill"), NULL
}
100 * Defines the menu entries for the Options sub-menu
102 * These options will be placed at the beginning of the menu, the rest will
103 * be populated with the Window Shortcut possibilities
112 static const char *const menu_options_entries
[] = {
113 [WO_KEEP_ON_TOP
] = N_("Keep on top"),
114 [WO_KEEP_AT_BOTTOM
] = N_("Keep at bottom"),
115 [WO_OMNIPRESENT
] = N_("Omnipresent")
119 * Defines the menu entries for the Other maximization sub-menu
121 static const struct {
122 unsigned int indicator
;
124 unsigned int shortcut_idx
;
126 } menu_maximize_entries
[] = {
127 { MI_SNAP_V
, N_("Vertically"), WKBD_VMAXIMIZE
, MAX_VERTICAL
},
128 { MI_SNAP_H
, N_("Horizontally"), WKBD_HMAXIMIZE
, MAX_HORIZONTAL
},
129 { MI_SNAP_LH
, N_("Left half"), WKBD_LHMAXIMIZE
, MAX_VERTICAL
| MAX_LEFTHALF
},
130 { MI_SNAP_RH
, N_("Right half"), WKBD_RHMAXIMIZE
, MAX_VERTICAL
| MAX_RIGHTHALF
},
131 { MI_SNAP_TH
, N_("Top half"), WKBD_THMAXIMIZE
, MAX_HORIZONTAL
| MAX_TOPHALF
},
132 { MI_SNAP_BH
, N_("Bottom half"), WKBD_BHMAXIMIZE
, MAX_HORIZONTAL
| MAX_BOTTOMHALF
},
133 { MI_SNAP_TL
, N_("Top left"), WKBD_LTCMAXIMIZE
, MAX_LEFTHALF
| MAX_TOPHALF
},
134 { MI_SNAP_TR
, N_("Top right"), WKBD_RTCMAXIMIZE
, MAX_RIGHTHALF
| MAX_TOPHALF
},
135 { MI_SNAP_BL
, N_("Bottom left"), WKBD_LBCMAXIMIZE
, MAX_LEFTHALF
| MAX_BOTTOMHALF
},
136 { MI_SNAP_BR
, N_("Bottom right"), WKBD_RBCMAXIMIZE
, MAX_RIGHTHALF
| MAX_BOTTOMHALF
},
137 { MI_SNAP_TILED
, N_("Tiled"), WKBD_MAXIMUS
, MAX_MAXIMUS
}
140 static void updateOptionsMenu(WMenu
* menu
, WWindow
* wwin
);
142 static void execWindowOptionCommand(WMenu
* menu
, WMenuEntry
* entry
)
144 WWindow
*wwin
= (WWindow
*) entry
->clientdata
;
146 /* Parameter not used, but tell the compiler that it is ok */
149 switch (entry
->order
) {
151 if (wwin
->frame
->core
->stacking
->window_level
!= WMFloatingLevel
)
152 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
154 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
157 case WO_KEEP_AT_BOTTOM
:
158 if (wwin
->frame
->core
->stacking
->window_level
!= WMSunkenLevel
)
159 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
161 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
165 wWindowSetOmnipresent(wwin
, !wwin
->flags
.omnipresent
);
170 static void execMaximizeCommand(WMenu
* menu
, WMenuEntry
* entry
)
172 WWindow
*wwin
= (WWindow
*) entry
->clientdata
;
174 /* Parameter not used, but tell the compiler that it is ok */
177 handleMaximize(wwin
, menu_maximize_entries
[entry
->order
].maxim_direction
);
180 static void updateUnmaximizeShortcut(WMenuEntry
* entry
, int flags
)
184 switch (flags
& (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
)) {
186 key
= WKBD_HMAXIMIZE
;
190 key
= WKBD_VMAXIMIZE
;
193 case MAX_LEFTHALF
| MAX_VERTICAL
:
194 key
= WKBD_LHMAXIMIZE
;
197 case MAX_RIGHTHALF
| MAX_VERTICAL
:
198 key
= WKBD_RHMAXIMIZE
;
201 case MAX_TOPHALF
| MAX_HORIZONTAL
:
202 key
= WKBD_THMAXIMIZE
;
205 case MAX_BOTTOMHALF
| MAX_HORIZONTAL
:
206 key
= WKBD_BHMAXIMIZE
;
209 case MAX_LEFTHALF
| MAX_TOPHALF
:
210 key
= WKBD_LTCMAXIMIZE
;
213 case MAX_RIGHTHALF
| MAX_TOPHALF
:
214 key
= WKBD_RTCMAXIMIZE
;
217 case MAX_LEFTHALF
| MAX_BOTTOMHALF
:
218 key
= WKBD_LBCMAXIMIZE
;
221 case MAX_RIGHTHALF
| MAX_BOTTOMHALF
:
222 key
= WKBD_RBCMAXIMIZE
;
234 entry
->rtext
= GetShortcutKey(wKeyBindings
[key
]);
237 static void execMenuCommand(WMenu
* menu
, WMenuEntry
* entry
)
239 WWindow
*wwin
= (WWindow
*) entry
->clientdata
;
242 CloseWindowMenu(menu
->frame
->screen_ptr
);
244 switch (entry
->order
) {
246 /* send delete message */
247 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
,
248 w_global
.timestamp
.last_event
);
253 if (wPreferences
.dont_confirm_kill
254 || wMessageDialog(menu
->frame
->screen_ptr
, _("Kill Application"),
256 ("This will kill the application.\nAny unsaved changes will be lost.\nPlease confirm."),
257 _("Yes"), _("No"), NULL
) == WAPRDefault
) {
258 if (!wwin
->flags
.destroyed
)
265 if (wwin
->flags
.miniaturized
) {
266 wDeiconifyWindow(wwin
);
268 if (wwin
->protocols
.MINIATURIZE_WINDOW
) {
269 wClientSendProtocol(wwin
, w_global
.atom
.gnustep
.wm_miniaturize_window
,
270 w_global
.timestamp
.last_event
);
272 wIconifyWindow(wwin
);
278 if (wwin
->flags
.maximized
)
279 wUnmaximizeWindow(wwin
);
281 wMaximizeWindow(wwin
, MAX_VERTICAL
| MAX_HORIZONTAL
,
282 wGetHeadForWindow(wwin
));
286 if (wwin
->flags
.shaded
)
287 wUnshadeWindow(wwin
);
293 if (!wwin
->flags
.miniaturized
)
294 wSelectWindow(wwin
, !wwin
->flags
.selected
);
296 wIconSelect(wwin
->icon
);
300 wKeyboardMoveResizeWindow(wwin
);
304 wShowInspectorForWindow(wwin
);
308 (void) RelaunchWindow(wwin
);
312 wapp
= wApplicationOf(wwin
->main_window
);
313 wHideApplication(wapp
);
318 static void switchWSCommand(WMenu
* menu
, WMenuEntry
* entry
)
320 WWindow
*wwin
= (WWindow
*) entry
->clientdata
;
322 /* Parameter not used, but tell the compiler that it is ok */
325 wSelectWindow(wwin
, False
);
326 wWindowChangeWorkspace(wwin
, entry
->order
);
329 static void makeShortcutCommand(WMenu
* menu
, WMenuEntry
* entry
)
331 WWindow
*wwin
= (WWindow
*) entry
->clientdata
;
332 WScreen
*scr
= wwin
->screen_ptr
;
333 int index
= entry
->order
- wlengthof(menu_options_entries
);
335 /* Parameter not used, but tell the compiler that it is ok */
338 if (scr
->shortcutWindows
[index
]) {
339 WMFreeArray(scr
->shortcutWindows
[index
]);
340 scr
->shortcutWindows
[index
] = NULL
;
343 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
344 scr
->shortcutWindows
[index
] = WMDuplicateArray(scr
->selected_windows
);
345 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
346 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
348 scr
->shortcutWindows
[index
] = WMCreateArray(4);
349 WMAddToArray(scr
->shortcutWindows
[index
], wwin
);
352 wSelectWindow(wwin
, !wwin
->flags
.selected
);
355 wSelectWindow(wwin
, !wwin
->flags
.selected
);
359 static void updateWorkspaceMenu(WMenu
* menu
)
361 WScreen
*scr
= menu
->frame
->screen_ptr
;
362 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
366 for (i
= 0; i
< scr
->workspace_count
; i
++) {
367 if (i
< menu
->entry_no
) {
369 entry
= menu
->entries
[i
];
370 if (strcmp(entry
->text
, scr
->workspaces
[i
]->name
) != 0) {
372 strncpy(title
, scr
->workspaces
[i
]->name
, MAX_WORKSPACENAME_WIDTH
);
373 title
[MAX_WORKSPACENAME_WIDTH
] = 0;
374 menu
->entries
[i
]->text
= wstrdup(title
);
375 menu
->entries
[i
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_MOVE_WORKSPACE1
+ i
]);
376 menu
->flags
.realized
= 0;
379 strncpy(title
, scr
->workspaces
[i
]->name
, MAX_WORKSPACENAME_WIDTH
);
380 title
[MAX_WORKSPACENAME_WIDTH
] = 0;
382 entry
= wMenuAddCallback(menu
, title
, switchWSCommand
, NULL
);
383 entry
->rtext
= GetShortcutKey(wKeyBindings
[WKBD_MOVE_WORKSPACE1
+ i
]);
385 menu
->flags
.realized
= 0;
388 /* workspace shortcut labels */
389 if (i
/ 10 == scr
->current_workspace
/ 10)
390 entry
->rtext
= GetShortcutKey(wKeyBindings
[WKBD_MOVE_WORKSPACE1
+ (i
% 10)]);
395 if (!menu
->flags
.realized
)
399 static void updateMakeShortcutMenu(WMenu
* menu
, WWindow
* wwin
)
401 WMenu
*smenu
= menu
->cascades
[menu
->entries
[MC_OPTIONS
]->cascade
];
409 for (i
= wlengthof(menu_options_entries
); i
< smenu
->entry_no
; i
++) {
410 int shortcutNo
= i
- wlengthof(menu_options_entries
);
411 WMenuEntry
*entry
= smenu
->entries
[i
];
412 WMArray
*shortSelWindows
= wwin
->screen_ptr
->shortcutWindows
[shortcutNo
];
414 snprintf(buffer
, sizeof(buffer
), _("Set Shortcut %i"), shortcutNo
+ 1);
416 if (!shortSelWindows
) {
417 entry
->flags
.indicator_on
= 0;
419 entry
->flags
.indicator_on
= 1;
420 if (WMCountInArray(shortSelWindows
, wwin
))
421 entry
->flags
.indicator_type
= MI_DIAMOND
;
423 entry
->flags
.indicator_type
= MI_CHECK
;
426 if (strcmp(buffer
, entry
->text
) != 0) {
428 entry
->text
= wstrdup(buffer
);
429 smenu
->flags
.realized
= 0;
432 kcode
= wKeyBindings
[WKBD_WINDOW1
+ shortcutNo
].keycode
;
437 tmp
= GetShortcutKey(wKeyBindings
[WKBD_WINDOW1
+ shortcutNo
]);
439 if (entry
->rtext
!= NULL
) {
440 /* There was a shortcut, but there is no more */
443 smenu
->flags
.realized
= 0;
445 } else if (entry
->rtext
== NULL
) {
446 /* There was no shortcut, but there is one now */
448 smenu
->flags
.realized
= 0;
449 } else if (strcmp(tmp
, entry
->rtext
) != 0) {
450 /* There was a shortcut, but it has changed */
453 smenu
->flags
.realized
= 0;
455 /* There was a shortcut but it did not change */
458 wMenuSetEnabled(smenu
, i
, True
);
460 wMenuSetEnabled(smenu
, i
, False
);
464 smenu
->flags
.realized
= 0;
467 entry
->clientdata
= wwin
;
469 if (!smenu
->flags
.realized
)
473 static void updateOptionsMenu(WMenu
* menu
, WWindow
* wwin
)
475 WMenu
*smenu
= menu
->cascades
[menu
->entries
[MC_OPTIONS
]->cascade
];
477 /* keep on top check */
478 smenu
->entries
[WO_KEEP_ON_TOP
]->clientdata
= wwin
;
479 smenu
->entries
[WO_KEEP_ON_TOP
]->flags
.indicator_on
=
480 (wwin
->frame
->core
->stacking
->window_level
== WMFloatingLevel
) ? 1 : 0;
481 wMenuSetEnabled(smenu
, WO_KEEP_ON_TOP
, !wwin
->flags
.miniaturized
);
482 smenu
->entries
[WO_KEEP_ON_TOP
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_KEEP_ON_TOP
]);
484 /* keep at bottom check */
485 smenu
->entries
[WO_KEEP_AT_BOTTOM
]->clientdata
= wwin
;
486 smenu
->entries
[WO_KEEP_AT_BOTTOM
]->flags
.indicator_on
=
487 (wwin
->frame
->core
->stacking
->window_level
== WMSunkenLevel
) ? 1 : 0;
488 wMenuSetEnabled(smenu
, WO_KEEP_AT_BOTTOM
, !wwin
->flags
.miniaturized
);
489 smenu
->entries
[WO_KEEP_AT_BOTTOM
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_KEEP_AT_BOTTOM
]);
491 /* omnipresent check */
492 smenu
->entries
[WO_OMNIPRESENT
]->clientdata
= wwin
;
493 smenu
->entries
[WO_OMNIPRESENT
]->flags
.indicator_on
= IS_OMNIPRESENT(wwin
);
494 smenu
->entries
[WO_OMNIPRESENT
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_OMNIPRESENT
]);
496 smenu
->flags
.realized
= 0;
500 static void updateMaximizeMenu(WMenu
* menu
, WWindow
* wwin
)
502 WMenu
*smenu
= menu
->cascades
[menu
->entries
[MC_OTHERMAX
]->cascade
];
505 for (i
= 0; i
< smenu
->entry_no
; i
++) {
506 smenu
->entries
[i
]->clientdata
= wwin
;
507 smenu
->entries
[i
]->rtext
= GetShortcutKey(wKeyBindings
[menu_maximize_entries
[i
].shortcut_idx
]);
510 smenu
->flags
.realized
= 0;
514 static WMenu
*makeWorkspaceMenu(WScreen
* scr
)
518 menu
= wMenuCreate(scr
, NULL
, False
);
520 wwarning(_("could not create submenu for window menu"));
524 updateWorkspaceMenu(menu
);
527 * The Workspace Menu is made visible in the screen structure because
528 * it is updated when there is a change on workspaces. This was done
529 * to be efficient, avoiding re-generating completely the window menu
530 * and its sub-menus every time it is needed.
532 scr
->workspace_submenu
= menu
;
537 static WMenu
*makeOptionsMenu(WScreen
* scr
)
543 menu
= wMenuCreate(scr
, NULL
, False
);
545 wwarning(_("could not create submenu for window menu"));
549 for (i
= 0; i
< wlengthof(menu_options_entries
); i
++) {
550 entry
= wMenuAddCallback(menu
, _(menu_options_entries
[i
]), execWindowOptionCommand
, NULL
);
551 entry
->flags
.indicator
= 1;
552 entry
->flags
.indicator_type
= MI_CHECK
;
555 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
556 entry
= wMenuAddCallback(menu
, "", makeShortcutCommand
, NULL
);
557 entry
->flags
.indicator
= 1;
563 static WMenu
*makeMaximizeMenu(WScreen
* scr
)
569 menu
= wMenuCreate(scr
, NULL
, False
);
571 wwarning(_("could not create submenu for window menu"));
575 for (i
= 0; i
< wlengthof(menu_maximize_entries
); i
++) {
576 entry
= wMenuAddCallback(menu
, _(menu_maximize_entries
[i
].label
), execMaximizeCommand
, NULL
);
577 entry
->flags
.indicator
= entry
->flags
.indicator_on
= 1;
578 entry
->flags
.indicator_type
= menu_maximize_entries
[i
].indicator
;
584 static WMenu
*createWindowMenu(WScreen
* scr
)
589 menu
= wMenuCreate(scr
, NULL
, False
);
591 for (i
= 0; i
< wlengthof(window_menu_entries
); i
++) {
594 entry
= wMenuAddCallback(menu
, _(window_menu_entries
[i
].label
),
595 (window_menu_entries
[i
].generate_submenu
== NULL
)?execMenuCommand
:NULL
,
597 if (window_menu_entries
[i
].generate_submenu
!= NULL
) {
600 submenu
= window_menu_entries
[i
].generate_submenu(scr
);
601 wMenuEntrySetCascade(menu
, entry
, submenu
);
608 void CloseWindowMenu(WScreen
* scr
)
610 if (scr
->window_menu
) {
611 if (scr
->window_menu
->flags
.mapped
)
612 wMenuUnmap(scr
->window_menu
);
614 if (scr
->window_menu
->entries
[0]->clientdata
) {
615 WWindow
*wwin
= (WWindow
*) scr
->window_menu
->entries
[0]->clientdata
;
617 wwin
->flags
.menu_open_for_me
= 0;
619 scr
->window_menu
->entries
[0]->clientdata
= NULL
;
623 static void updateMenuForWindow(WMenu
* menu
, WWindow
* wwin
)
625 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
626 WScreen
*scr
= wwin
->screen_ptr
;
629 updateOptionsMenu(menu
, wwin
);
630 updateMaximizeMenu(menu
, wwin
);
632 updateMakeShortcutMenu(menu
, wwin
);
634 wMenuSetEnabled(menu
, MC_HIDE
, wapp
!= NULL
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
));
636 wMenuSetEnabled(menu
, MC_CLOSE
, (wwin
->protocols
.DELETE_WINDOW
&& !WFLAGP(wwin
, no_closable
)));
638 if (wwin
->flags
.miniaturized
) {
639 static char *text
= NULL
;
641 text
= _("Deminiaturize");
643 menu
->entries
[MC_MINIATURIZE
]->text
= text
;
645 static char *text
= NULL
;
647 text
= _("Miniaturize");
649 menu
->entries
[MC_MINIATURIZE
]->text
= text
;
652 wMenuSetEnabled(menu
, MC_MINIATURIZE
, !WFLAGP(wwin
, no_miniaturizable
));
654 if (wwin
->flags
.maximized
) {
655 static char *text
= NULL
;
657 text
= _("Unmaximize");
659 menu
->entries
[MC_MAXIMIZE
]->text
= text
;
660 updateUnmaximizeShortcut(menu
->entries
[MC_MAXIMIZE
], wwin
->flags
.maximized
);
662 static char *text
= NULL
;
664 text
= _("Maximize");
666 menu
->entries
[MC_MAXIMIZE
]->text
= text
;
667 menu
->entries
[MC_MAXIMIZE
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_MAXIMIZE
]);
669 wMenuSetEnabled(menu
, MC_MAXIMIZE
, IS_RESIZABLE(wwin
));
671 wMenuSetEnabled(menu
, MC_MOVERESIZE
, IS_RESIZABLE(wwin
)
672 && !wwin
->flags
.miniaturized
);
674 if (wwin
->flags
.shaded
) {
675 static char *text
= NULL
;
679 menu
->entries
[MC_SHADE
]->text
= text
;
681 static char *text
= NULL
;
685 menu
->entries
[MC_SHADE
]->text
= text
;
688 wMenuSetEnabled(menu
, MC_SHADE
, !WFLAGP(wwin
, no_shadeable
)
689 && !wwin
->flags
.miniaturized
);
691 if (wwin
->flags
.selected
) {
692 static char *text
= NULL
;
694 text
= _("Deselect");
696 menu
->entries
[MC_SELECT
]->text
= text
;
698 static char *text
= NULL
;
702 menu
->entries
[MC_SELECT
]->text
= text
;
705 wMenuSetEnabled(menu
, MC_CHANGEWKSPC
, !IS_OMNIPRESENT(wwin
));
707 if (!wwin
->flags
.inspector_open
) {
708 wMenuSetEnabled(menu
, MC_PROPERTIES
, True
);
710 wMenuSetEnabled(menu
, MC_PROPERTIES
, False
);
713 /* Update shortcut labels except for (Un)Maximize which is
714 * handled separately.
716 menu
->entries
[MC_MINIATURIZE
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_MINIATURIZE
]);
717 menu
->entries
[MC_SHADE
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_SHADE
]);
718 menu
->entries
[MC_HIDE
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_HIDE
]);
719 menu
->entries
[MC_MOVERESIZE
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_MOVERESIZE
]);
720 menu
->entries
[MC_SELECT
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_SELECT
]);
721 menu
->entries
[MC_RELAUNCH
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_RELAUNCH
]);
722 menu
->entries
[MC_CLOSE
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_CLOSE
]);
724 /* set the client data of the entries to the window */
725 for (i
= 0; i
< menu
->entry_no
; i
++) {
726 menu
->entries
[i
]->clientdata
= wwin
;
729 for (i
= 0; i
< scr
->workspace_submenu
->entry_no
; i
++) {
730 scr
->workspace_submenu
->entries
[i
]->clientdata
= wwin
;
731 if (i
== scr
->current_workspace
)
732 wMenuSetEnabled(scr
->workspace_submenu
, i
, False
);
734 wMenuSetEnabled(scr
->workspace_submenu
, i
, True
);
737 menu
->flags
.realized
= 0;
741 static WMenu
*open_window_menu_core(WWindow
*wwin
)
743 WScreen
*scr
= wwin
->screen_ptr
;
746 wwin
->flags
.menu_open_for_me
= 1;
748 if (!scr
->window_menu
) {
749 scr
->window_menu
= createWindowMenu(scr
);
751 /* hack to save some memory allocation/deallocation */
752 wfree(scr
->window_menu
->entries
[MC_MINIATURIZE
]->text
);
753 wfree(scr
->window_menu
->entries
[MC_MAXIMIZE
]->text
);
754 wfree(scr
->window_menu
->entries
[MC_SHADE
]->text
);
755 wfree(scr
->window_menu
->entries
[MC_SELECT
]->text
);
757 updateWorkspaceMenu(scr
->workspace_submenu
);
760 menu
= scr
->window_menu
;
761 if (menu
->flags
.mapped
) {
763 if (menu
->entries
[0]->clientdata
== wwin
)
767 updateMenuForWindow(menu
, wwin
);
772 static void prepare_menu_position(WMenu
*menu
, int *x
, int *y
)
776 rect
= wGetRectForHead(menu
->frame
->screen_ptr
,
777 wGetHeadForPointerLocation(menu
->frame
->screen_ptr
));
778 if (*x
< rect
.pos
.x
- menu
->frame
->core
->width
/ 2)
779 *x
= rect
.pos
.x
- menu
->frame
->core
->width
/ 2;
784 void OpenWindowMenu(WWindow
*wwin
, int x
, int y
, int keyboard
)
788 menu
= open_window_menu_core(wwin
);
792 /* Specific menu position */
793 x
-= menu
->frame
->core
->width
/ 2;
794 if (x
+ menu
->frame
->core
->width
> wwin
->frame_x
+ wwin
->frame
->core
->width
)
795 x
= wwin
->frame_x
+ wwin
->frame
->core
->width
- menu
->frame
->core
->width
;
796 if (x
< wwin
->frame_x
)
799 /* Common menu position */
800 prepare_menu_position(menu
, &x
, &y
);
802 if (!wwin
->flags
.internal_window
)
803 wMenuMapAt(menu
, x
, y
, keyboard
);
806 void OpenWindowMenu2(WWindow
*wwin
, int x
, int y
, int keyboard
)
810 WScreen
*scr
= wwin
->screen_ptr
;
812 menu
= open_window_menu_core(wwin
);
816 /* Specific menu position */
817 for (i
= 0; i
< scr
->workspace_submenu
->entry_no
; i
++) {
818 scr
->workspace_submenu
->entries
[i
]->clientdata
= wwin
;
819 wMenuSetEnabled(scr
->workspace_submenu
, i
, True
);
822 x
-= menu
->frame
->core
->width
/ 2;
824 /* Common menu position */
825 prepare_menu_position(menu
, &x
, &y
);
827 if (!wwin
->flags
.internal_window
)
828 wMenuMapAt(menu
, x
, y
, keyboard
);
831 void OpenMiniwindowMenu(WWindow
* wwin
, int x
, int y
)
835 menu
= open_window_menu_core(wwin
);
839 x
-= menu
->frame
->core
->width
/ 2;
841 wMenuMapAt(menu
, x
, y
, False
);
844 void DestroyWindowMenu(WScreen
*scr
)
846 if (scr
->window_menu
) {
847 scr
->window_menu
->entries
[MC_MINIATURIZE
]->text
= NULL
;
848 scr
->window_menu
->entries
[MC_MAXIMIZE
]->text
= NULL
;
849 scr
->window_menu
->entries
[MC_SHADE
]->text
= NULL
;
850 scr
->window_menu
->entries
[MC_SELECT
]->text
= NULL
;
851 wMenuDestroy(scr
->window_menu
, True
);
852 scr
->window_menu
= NULL
;