2 * Window Maker window manager
4 * Copyright (c) 1997 Shige Abe and
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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
33 #include <X11/Xutil.h>
35 #include "WindowMaker.h"
41 #include "workspace.h"
44 /********* Global Variables *******/
45 extern WPreferences wPreferences
;
46 extern Time LastTimestamp
;
52 * - Needs to check if already in the right workspace before
53 * calling wChangeWorkspace?
56 * Switch to correct workspace
58 * If iconified then deiconify else focus/raise.
61 focusWindow(WMenu
*menu
, WMenuEntry
*entry
)
67 wwin
= (WWindow
*)entry
->clientdata
;
68 scr
= wwin
->screen_ptr
;
70 wMakeWindowVisible(wwin
);
75 /* bring window back to visible area */
76 move
= wScreenBringInside(scr
, &x
, &y
, wwin
->frame
->core
->width
,
77 wwin
->frame
->core
->height
);
80 wWindowConfigure(wwin
, x
, y
, wwin
->client
.width
, wwin
->client
.height
);
90 OpenSwitchMenu(WScreen
*scr
, int x
, int y
, int keyboard
)
92 WMenu
*switchmenu
= scr
->switch_menu
;
96 if (switchmenu
->flags
.mapped
) {
97 if (!switchmenu
->flags
.buttoned
) {
98 wMenuUnmap(switchmenu
);
100 wRaiseFrame(switchmenu
->frame
->core
);
103 wMenuMapAt(switchmenu
, 0, 0, True
);
105 wMenuMapCopyAt(switchmenu
,
106 x
-switchmenu
->frame
->core
->width
/2, y
);
109 wMenuMapAt(switchmenu
, x
-switchmenu
->frame
->core
->width
/2, y
,
114 switchmenu
= wMenuCreate(scr
,_("Windows"),True
);
115 scr
->switch_menu
= switchmenu
;
118 wwin
= scr
->focused_window
;
120 UpdateSwitchMenu(scr
, wwin
, ACTION_ADD
);
126 if (!switchmenu
->flags
.realized
)
127 wMenuRealize(switchmenu
);
128 wMenuMapAt(switchmenu
, x
-switchmenu
->frame
->core
->width
/2, y
,
135 menuIndexForWindow(WMenu
*menu
, WWindow
*wwin
, int old_pos
)
139 if (menu
->entry_no
== 0)
142 #define WS(i) ((WWindow*)menu->entries[i]->clientdata)->frame->workspace
144 if (WS(old_pos
) >= wwin
->frame
->workspace
145 && (old_pos
== 0 || WS(old_pos
-1) <= wwin
->frame
->workspace
)) {
151 for (idx
= 0; idx
< menu
->entry_no
; idx
++) {
152 WWindow
*tw
= (WWindow
*)menu
->entries
[idx
]->clientdata
;
154 if (!IS_OMNIPRESENT(tw
)
155 && tw
->frame
->workspace
> wwin
->frame
->workspace
) {
168 UpdateSwitchMenu(WScreen
*scr
, WWindow
*wwin
, int action
)
170 WMenu
*switchmenu
= scr
->switch_menu
;
172 char title
[MAX_MENU_TEXT_LENGTH
+6];
174 int checkVisibility
= 0;
176 if (!wwin
->screen_ptr
->switch_menu
)
179 * This menu is updated under the following conditions:
181 * 1. When a window is created.
182 * 2. When a window is destroyed.
184 * 3. When a window changes it's title.
185 * 4. When a window changes its workspace.
187 if (action
== ACTION_ADD
) {
191 if (wwin
->flags
.internal_window
|| WFLAGP(wwin
, skip_window_list
))
194 if (wwin
->frame
->title
)
195 sprintf(title
, "%s", wwin
->frame
->title
);
197 sprintf(title
, "%s", DEF_WINDOW_TITLE
);
198 #ifdef DRAWSTRING_PLUGIN
199 t
= ShrinkString(scr
->menu_entry_font
, title
, MAX_WINDOWLIST_WIDTH
,
200 scr
->drawstring_func
[W_STRING_MTEXT
]);
202 t
= ShrinkString(scr
->menu_entry_font
, title
, MAX_WINDOWLIST_WIDTH
);
205 if (IS_OMNIPRESENT(wwin
))
208 idx
= menuIndexForWindow(switchmenu
, wwin
, -1);
211 entry
= wMenuInsertCallback(switchmenu
, idx
, t
, focusWindow
, wwin
);
214 entry
->flags
.indicator
= 1;
215 entry
->rtext
= wmalloc(MAX_WORKSPACENAME_WIDTH
+8);
216 if (IS_OMNIPRESENT(wwin
))
217 sprintf(entry
->rtext
, "[*]");
219 sprintf(entry
->rtext
, "[%s]",
220 scr
->workspaces
[wwin
->frame
->workspace
]->name
);
222 if (wwin
->flags
.hidden
) {
223 entry
->flags
.indicator_type
= MI_HIDDEN
;
224 entry
->flags
.indicator_on
= 1;
225 } else if (wwin
->flags
.miniaturized
) {
226 entry
->flags
.indicator_type
= MI_MINIWINDOW
;
227 entry
->flags
.indicator_on
= 1;
228 } else if (wwin
->flags
.focused
) {
229 entry
->flags
.indicator_type
= MI_DIAMOND
;
230 entry
->flags
.indicator_on
= 1;
231 } else if (wwin
->flags
.shaded
) {
232 entry
->flags
.indicator_type
= MI_SHADED
;
233 entry
->flags
.indicator_on
= 1;
236 wMenuRealize(switchmenu
);
240 for (i
=0; i
<switchmenu
->entry_no
; i
++) {
241 entry
= switchmenu
->entries
[i
];
242 /* this is the entry that was changed */
243 if (entry
->clientdata
== wwin
) {
246 wMenuRemoveItem(switchmenu
, i
);
247 wMenuRealize(switchmenu
);
255 if (wwin
->frame
->title
)
256 sprintf(title
, "%s", wwin
->frame
->title
);
258 sprintf(title
, "%s", DEF_WINDOW_TITLE
);
260 #ifdef DRAWSTRING_PLUGIN
261 t
= ShrinkString(scr
->menu_entry_font
, title
, MAX_WINDOWLIST_WIDTH
,
262 scr
->drawstring_func
[W_STRING_MTEXT
]);
264 t
= ShrinkString(scr
->menu_entry_font
, title
, MAX_WINDOWLIST_WIDTH
);
268 wMenuRealize(switchmenu
);
272 case ACTION_CHANGE_WORKSPACE
:
278 if (IS_OMNIPRESENT(wwin
)) {
279 sprintf(entry
->rtext
, "[*]");
281 sprintf(entry
->rtext
, "[%s]",
282 scr
->workspaces
[wwin
->frame
->workspace
]->name
);
290 it
= entry
->flags
.indicator_type
;
291 ion
= entry
->flags
.indicator_on
;
293 wMenuRemoveItem(switchmenu
, i
);
295 if (!IS_OMNIPRESENT(wwin
) && idx
< 0) {
296 idx
= menuIndexForWindow(switchmenu
, wwin
, i
);
299 entry
= wMenuInsertCallback(switchmenu
, idx
, t
,
303 entry
->flags
.indicator
= 1;
304 entry
->flags
.indicator_type
= it
;
305 entry
->flags
.indicator_on
= ion
;
307 wMenuRealize(switchmenu
);
312 case ACTION_CHANGE_STATE
:
313 if (wwin
->flags
.hidden
) {
314 entry
->flags
.indicator_type
= MI_HIDDEN
;
315 entry
->flags
.indicator_on
= 1;
316 } else if (wwin
->flags
.miniaturized
) {
317 entry
->flags
.indicator_type
= MI_MINIWINDOW
;
318 entry
->flags
.indicator_on
= 1;
319 } else if (wwin
->flags
.shaded
&& !wwin
->flags
.focused
) {
320 entry
->flags
.indicator_type
= MI_SHADED
;
321 entry
->flags
.indicator_on
= 1;
323 entry
->flags
.indicator_on
= wwin
->flags
.focused
;
324 entry
->flags
.indicator_type
= MI_DIAMOND
;
332 if (checkVisibility
) {
335 tmp
= switchmenu
->frame
->top_width
+ 5;
336 /* if menu got unreachable, bring it to a visible place */
337 if (switchmenu
->frame_x
< tmp
- (int)switchmenu
->frame
->core
->width
) {
338 wMenuMove(switchmenu
, tmp
- (int)switchmenu
->frame
->core
->width
,
339 switchmenu
->frame_y
, False
);
342 wMenuPaint(switchmenu
);
348 UpdateSwitchMenuWorkspace(WScreen
*scr
, int workspace
)
350 WMenu
*menu
= scr
->switch_menu
;
357 for (i
=0; i
<menu
->entry_no
; i
++) {
358 wwin
= (WWindow
*)menu
->entries
[i
]->clientdata
;
360 if (wwin
->frame
->workspace
==workspace
361 && !IS_OMNIPRESENT(wwin
)) {
362 if (IS_OMNIPRESENT(wwin
))
363 sprintf(menu
->entries
[i
]->rtext
, "[*]");
365 sprintf(menu
->entries
[i
]->rtext
, "[%s]",
366 scr
->workspaces
[wwin
->frame
->workspace
]->name
);
367 menu
->flags
.realized
= 0;
370 if (!menu
->flags
.realized
)