2 * Window Maker window manager
4 * Copyright (c) 1997-2004 Alfredo K. Kojima
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
26 #include "WindowMaker.h"
32 #include "switchpanel.h"
51 extern WPreferences wPreferences
;
53 #define ICON_EXTRASPACE 4
55 static void addIconForWindow(WSwitchPanel
*panel
, WWindow
*wwin
, int iconWidth
)
57 WMLabel
*label
= WMCreateLabel(panel
->hbox
);
58 WMAddBoxSubviewAtEnd(panel
->hbox
, WMWidgetView(label
), False
, True
, iconWidth
+ ICON_EXTRASPACE
, 0, 0);
61 WMScreen
*wscr
= WMWidgetScreen(label
);
63 if (!WFLAGP(wwin
, always_user_icon
) && wwin
->net_icon_image
)
64 image
= RRetainImage(wwin
->net_icon_image
);
66 image
= wDefaultGetImage(panel
->scr
, wwin
->wm_instance
, wwin
->wm_class
);
69 if (image
&& (abs(image
->width
- iconWidth
) > 4 || abs(image
->height
- iconWidth
) > 4)) {
72 nimage
= RScaleImage(image
, iconWidth
, (image
->height
* iconWidth
/ image
->width
));
78 pixmap
= WMCreatePixmapFromRImage(wscr
, image
, 100);
83 char *file
= wDefaultGetIconFile(panel
->scr
, NULL
, NULL
, False
);
85 char *path
= FindImage(wPreferences
.icon_path
, file
);
87 image
= RLoadImage(panel
->scr
->rcontext
, path
, 0);
90 panel
->defIcon
= WMCreatePixmapFromRImage(wscr
, image
, 100);
97 pixmap
= WMRetainPixmap(panel
->defIcon
);
103 WMSetLabelImage(label
, pixmap
);
104 WMSetLabelImagePosition(label
, WIPImageOnly
);
105 WMReleasePixmap(pixmap
);
108 WMAddToArray(panel
->icons
, label
);
112 WSwitchPanel
*wInitSwitchPanel(WScreen
*scr
, int workspace
)
115 WSwitchPanel
*panel
= wmalloc(sizeof(WSwitchPanel
));
123 panel
->defIcon
= NULL
;
125 panel
->normalColor
= WMGrayColor(scr
->wmscreen
);
126 panel
->selectColor
= WMWhiteColor(scr
->wmscreen
);
129 panel
->windows
= WMCreateArray(10);
131 for (wwin
= scr
->focused_window
; wwin
; wwin
= wwin
->prev
) {
132 if (wwin
->frame
->workspace
== workspace
&& wWindowCanReceiveFocus(wwin
) &&
133 (!WFLAGP(wwin
, skip_window_list
) || wwin
->flags
.internal_window
)) {
134 WMInsertInArray(panel
->windows
, 0, wwin
);
138 width
= (iconWidth
+ ICON_EXTRASPACE
)*WMGetArrayItemCount(panel
->windows
);
140 if (width
> WMScreenWidth(scr
->wmscreen
))
142 width
= WMScreenWidth(scr
->wmscreen
) - 100;
143 iconWidth
= width
/ WMGetArrayItemCount(panel
->windows
) - ICON_EXTRASPACE
;
148 /* if there are too many windows, don't bother trying to show the panel */
149 WMFreeArray(panel
->windows
);
154 height
= 48 + 20 + 10 + ICON_EXTRASPACE
;
156 panel
->icons
= WMCreateArray(WMGetArrayItemCount(panel
->windows
));
158 panel
->win
= WMCreateWindow(scr
->wmscreen
, "");
159 WMResizeWidget(panel
->win
, width
+ 10, height
);
162 WMFrame
*frame
= WMCreateFrame(panel
->win
);
163 WMSetFrameRelief(frame
, WRSimple
);
164 WMSetViewExpandsToParent(WMWidgetView(frame
), 0, 0, 0, 0);
166 vbox
= WMCreateBox(panel
->win
);
168 WMSetViewExpandsToParent(WMWidgetView(vbox
), 5, 5, 5, 5);
169 WMSetBoxHorizontal(vbox
, False
);
171 panel
->label
= WMCreateLabel(vbox
);
172 WMAddBoxSubviewAtEnd(vbox
, WMWidgetView(panel
->label
), False
, True
, 20, 0, 0);
173 if (scr
->focused_window
&& scr
->focused_window
->frame
->title
)
174 WMSetLabelText(panel
->label
, scr
->focused_window
->frame
->title
);
176 WMSetLabelText(panel
->label
, "");
179 WMFont
*boldFont
= WMBoldSystemFontOfSize(scr
->wmscreen
, 12);
181 WMSetLabelRelief(panel
->label
, WRSimple
);
182 WMSetLabelFont(panel
->label
, boldFont
);
183 color
= WMDarkGrayColor(scr
->wmscreen
);
184 WMSetWidgetBackgroundColor(panel
->label
, color
);
185 WMReleaseColor(color
);
186 color
= WMWhiteColor(scr
->wmscreen
);
187 WMSetLabelTextColor(panel
->label
, color
);
188 WMReleaseColor(color
);
190 WMReleaseFont(boldFont
);
193 panel
->hbox
= WMCreateBox(vbox
);
194 WMSetBoxHorizontal(panel
->hbox
, True
);
195 WMAddBoxSubviewAtEnd(vbox
, WMWidgetView(panel
->hbox
), True
, True
, 20, 0, 2);
197 WM_ITERATE_ARRAY(panel
->windows
, wwin
, i
) {
198 addIconForWindow(panel
, wwin
, iconWidth
);
201 WMMapSubwidgets(panel
->win
);
202 WMRealizeWidget(panel
->win
);
203 WMMapWidget(panel
->win
);
204 WMMoveWidget(panel
->win
,
205 (WMScreenWidth(scr
->wmscreen
) - (width
+10))/2,
206 (WMScreenHeight(scr
->wmscreen
) - height
)/2);
208 WMSetWidgetBackgroundColor(WMGetFromArray(panel
->icons
, 0),
215 void wSwitchPanelDestroy(WSwitchPanel
*panel
)
217 WMDestroyWidget(panel
->win
);
218 WMFreeArray(panel
->icons
);
219 WMFreeArray(panel
->windows
);
220 WMReleaseColor(panel
->selectColor
);
221 WMReleaseColor(panel
->normalColor
);
223 WMReleasePixmap(panel
->defIcon
);
228 WWindow
*wSwitchPanelSelectNext(WSwitchPanel
*panel
, int back
)
231 int count
= WMGetArrayItemCount(panel
->windows
);
234 label
= WMGetFromArray(panel
->icons
, panel
->current
);
235 WMSetWidgetBackgroundColor(label
, panel
->normalColor
);
236 WMSetLabelRelief(label
, WRFlat
);
239 panel
->current
= (count
+ panel
->current
- 1) % count
;
241 panel
->current
= (panel
->current
+ 1) % count
;
243 wwin
= WMGetFromArray(panel
->windows
, panel
->current
);
245 WMSetLabelText(panel
->label
, wwin
->frame
->title
);
247 label
= WMGetFromArray(panel
->icons
, panel
->current
);
248 WMSetWidgetBackgroundColor(label
, panel
->selectColor
);
249 WMSetLabelRelief(label
, WRSimple
);
256 WWindow
*wSwitchPanelHandleEvent(WSwitchPanel
*panel
, XEvent
*event
)
261 printf("%i %i\n", event
->xmotion
.x
, event
->xmotion
.y
);
263 WM_ITERATE_ARRAY(panel
->icons
, label
, i
) {
264 if (WMWidgetXID(label
) == event
->xmotion
.subwindow
)