]> Dogcows Code - chaz/openbox/blob - openbox/focus_cycle_popup.c
0f9bd75224a21d584df348318becd40e532004c2
[chaz/openbox] / openbox / focus_cycle_popup.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3 focus_cycle_popup.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
6
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.
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 See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #include "focus_cycle_popup.h"
21 #include "popup.h"
22 #include "client.h"
23 #include "screen.h"
24 #include "focus.h"
25 #include "openbox.h"
26 #include "config.h"
27 #include "window.h"
28 #include "event.h"
29 #include "render/render.h"
30
31 #include <X11/Xlib.h>
32 #include <glib.h>
33
34 /* Size of the icons, which can appear inside or outside of a hilite box */
35 #define ICON_SIZE (gint)config_theme_window_list_icon_size
36 /* Size of the hilite box around a window's icon */
37 #define HILITE_SIZE (ICON_SIZE + 2*HILITE_OFFSET)
38 /* Width of the outer ring around the hilite box */
39 #define HILITE_WIDTH 2
40 /* Space between the outer ring around the hilite box and the icon inside it */
41 #define HILITE_MARGIN 1
42 /* Total distance from the edge of the hilite box to the icon inside it */
43 #define HILITE_OFFSET (HILITE_WIDTH + HILITE_MARGIN)
44 /* Margin area around the outside of the dialog */
45 #define OUTSIDE_BORDER 3
46 /* Margin area around the text */
47 #define TEXT_BORDER 2
48 /* Scroll the list-mode list when the cursor gets within this many rows of the
49 top or bottom */
50 #define SCROLL_MARGIN 4
51
52 typedef struct _ObFocusCyclePopup ObFocusCyclePopup;
53 typedef struct _ObFocusCyclePopupTarget ObFocusCyclePopupTarget;
54
55 struct _ObFocusCyclePopupTarget
56 {
57 ObClient *client;
58 RrImage *icon;
59 gchar *text;
60 Window iconwin;
61 /* This is used when the popup is in list mode */
62 Window textwin;
63 };
64
65 struct _ObFocusCyclePopup
66 {
67 ObWindow obwin;
68 Window bg;
69
70 /* This is used when the popup is in icon mode */
71 Window icon_mode_text;
72
73 Window list_mode_up;
74 Window list_mode_down;
75
76 GList *targets;
77 gint n_targets;
78
79 const ObFocusCyclePopupTarget *last_target;
80
81 gint maxtextw;
82
83 /* How are the list is scrolled, in scroll mode */
84 gint scroll;
85
86 RrAppearance *a_bg;
87 RrAppearance *a_text;
88 RrAppearance *a_hilite_text;
89 RrAppearance *a_icon;
90 RrAppearance *a_arrow;
91
92 gboolean mapped;
93 ObFocusCyclePopupMode mode;
94 };
95
96 /*! This popup shows all possible windows */
97 static ObFocusCyclePopup popup;
98 /*! This popup shows a single window */
99 static ObIconPopup *single_popup;
100
101 static gchar *popup_get_name (ObClient *c);
102 static void popup_setup (ObFocusCyclePopup *p,
103 gboolean create_targets,
104 gboolean iconic_windows,
105 gboolean all_desktops,
106 gboolean dock_windows,
107 gboolean desktop_windows);
108 static void popup_render (ObFocusCyclePopup *p,
109 const ObClient *c);
110
111 static Window create_window(Window parent, guint bwidth, gulong mask,
112 XSetWindowAttributes *attr)
113 {
114 return XCreateWindow(obt_display, parent, 0, 0, 1, 1, bwidth,
115 RrDepth(ob_rr_inst), InputOutput,
116 RrVisual(ob_rr_inst), mask, attr);
117 }
118
119 void focus_cycle_popup_startup(gboolean reconfig)
120 {
121 XSetWindowAttributes attrib;
122 RrPixel32 *p;
123
124 single_popup = icon_popup_new();
125
126 popup.obwin.type = OB_WINDOW_CLASS_INTERNAL;
127 popup.a_bg = RrAppearanceCopy(ob_rr_theme->osd_bg);
128 popup.a_hilite_text = RrAppearanceCopy(ob_rr_theme->osd_hilite_label);
129 popup.a_text = RrAppearanceCopy(ob_rr_theme->osd_unhilite_label);
130 popup.a_icon = RrAppearanceCopy(ob_rr_theme->a_clear);
131 popup.a_arrow = RrAppearanceCopy(ob_rr_theme->a_clear_tex);
132
133 popup.a_hilite_text->surface.parent = popup.a_bg;
134 popup.a_text->surface.parent = popup.a_bg;
135 popup.a_icon->surface.parent = popup.a_bg;
136
137 popup.a_text->texture[0].data.text.justify = RR_JUSTIFY_LEFT;
138 popup.a_hilite_text->texture[0].data.text.justify = RR_JUSTIFY_LEFT;
139
140 /* 2 textures. texture[0] is the icon. texture[1] is the hilight, and
141 may or may not be used */
142 RrAppearanceAddTextures(popup.a_icon, 2);
143
144 RrAppearanceClearTextures(popup.a_icon);
145 popup.a_icon->texture[0].type = RR_TEXTURE_IMAGE;
146
147 RrAppearanceClearTextures(popup.a_arrow);
148 popup.a_arrow->texture[0].type = RR_TEXTURE_MASK;
149 popup.a_arrow->texture[0].data.mask.color =
150 ob_rr_theme->osd_text_active_color;
151
152 attrib.override_redirect = True;
153 attrib.border_pixel=RrColorPixel(ob_rr_theme->osd_border_color);
154 popup.bg = create_window(obt_root(ob_screen), ob_rr_theme->obwidth,
155 CWOverrideRedirect | CWBorderPixel, &attrib);
156
157 /* create the text window used for the icon-mode popup */
158 popup.icon_mode_text = create_window(popup.bg, 0, 0, NULL);
159
160 /* create the windows for the up and down arrows */
161 popup.list_mode_up = create_window(popup.bg, 0, 0, NULL);
162 popup.list_mode_down = create_window(popup.bg, 0, 0, NULL);
163
164 popup.targets = NULL;
165 popup.n_targets = 0;
166 popup.last_target = NULL;
167
168 /* set up the hilite texture for the icon */
169 popup.a_icon->texture[1].data.rgba.width = HILITE_SIZE;
170 popup.a_icon->texture[1].data.rgba.height = HILITE_SIZE;
171 popup.a_icon->texture[1].data.rgba.alpha = 0xff;
172 p = g_new(RrPixel32, HILITE_SIZE * HILITE_SIZE);
173 popup.a_icon->texture[1].data.rgba.data = p;
174
175 /* create the hilite under the target icon */
176 {
177 RrPixel32 color;
178 RrColor *tc;
179 gint x, y, o;
180
181 tc = ob_rr_theme->osd_text_active_color;
182 color = ((tc->r & 0xff) << RrDefaultRedOffset) +
183 ((tc->g & 0xff) << RrDefaultGreenOffset) +
184 ((tc->b & 0xff) << RrDefaultBlueOffset);
185
186 o = 0;
187 for (x = 0; x < HILITE_SIZE; x++)
188 for (y = 0; y < HILITE_SIZE; y++) {
189 guchar a;
190
191 if (x < HILITE_WIDTH ||
192 x >= HILITE_SIZE - HILITE_WIDTH ||
193 y < HILITE_WIDTH ||
194 y >= HILITE_SIZE - HILITE_WIDTH)
195 {
196 /* the border of the target */
197 a = 0x88;
198 } else {
199 /* the background of the target */
200 a = 0x22;
201 }
202
203 p[o++] = color + (a << RrDefaultAlphaOffset);
204 }
205 }
206
207 stacking_add(INTERNAL_AS_WINDOW(&popup));
208 window_add(&popup.bg, INTERNAL_AS_WINDOW(&popup));
209 }
210
211 void focus_cycle_popup_shutdown(gboolean reconfig)
212 {
213 icon_popup_free(single_popup);
214
215 window_remove(popup.bg);
216 stacking_remove(INTERNAL_AS_WINDOW(&popup));
217
218 while(popup.targets) {
219 ObFocusCyclePopupTarget *t = popup.targets->data;
220
221 RrImageUnref(t->icon);
222 g_free(t->text);
223 XDestroyWindow(obt_display, t->iconwin);
224 XDestroyWindow(obt_display, t->textwin);
225 g_free(t);
226
227 popup.targets = g_list_delete_link(popup.targets, popup.targets);
228 }
229
230 g_free(popup.a_icon->texture[1].data.rgba.data);
231 popup.a_icon->texture[1].data.rgba.data = NULL;
232
233 XDestroyWindow(obt_display, popup.list_mode_up);
234 XDestroyWindow(obt_display, popup.list_mode_down);
235 XDestroyWindow(obt_display, popup.icon_mode_text);
236 XDestroyWindow(obt_display, popup.bg);
237
238 RrAppearanceFree(popup.a_arrow);
239 RrAppearanceFree(popup.a_icon);
240 RrAppearanceFree(popup.a_hilite_text);
241 RrAppearanceFree(popup.a_text);
242 RrAppearanceFree(popup.a_bg);
243 }
244
245 static void popup_setup(ObFocusCyclePopup *p, gboolean create_targets,
246 gboolean iconic_windows, gboolean all_desktops,
247 gboolean dock_windows, gboolean desktop_windows)
248 {
249 gint maxwidth, n;
250 GList *it;
251
252 g_assert(p->targets == NULL);
253 g_assert(p->n_targets == 0);
254
255 /* make its width to be the width of all the possible titles */
256
257 /* build a list of all the valid focus targets and measure their strings,
258 and count them */
259 maxwidth = 0;
260 n = 0;
261 for (it = g_list_last(focus_order); it; it = g_list_previous(it)) {
262 ObClient *ft = it->data;
263
264 if (focus_valid_target(ft, TRUE,
265 iconic_windows,
266 all_desktops,
267 dock_windows,
268 desktop_windows,
269 FALSE))
270 {
271 gchar *text = popup_get_name(ft);
272
273 /* measure */
274 p->a_text->texture[0].data.text.string = text;
275 maxwidth = MAX(maxwidth, RrMinWidth(p->a_text));
276
277 if (!create_targets) {
278 g_free(text);
279 } else {
280 ObFocusCyclePopupTarget *t = g_new(ObFocusCyclePopupTarget, 1);
281
282 t->client = ft;
283 t->text = text;
284 t->icon = client_icon(t->client);
285 RrImageRef(t->icon); /* own the icon so it won't go away */
286 t->iconwin = create_window(p->bg, 0, 0, NULL);
287 t->textwin = create_window(p->bg, 0, 0, NULL);
288
289 p->targets = g_list_prepend(p->targets, t);
290 ++n;
291 }
292 }
293 }
294
295 p->n_targets = n;
296 p->maxtextw = maxwidth;
297 }
298
299 static gchar *popup_get_name(ObClient *c)
300 {
301 ObClient *p;
302 gchar *title;
303 const gchar *desk = NULL;
304 gchar *ret;
305
306 /* find our highest direct parent */
307 p = client_search_top_direct_parent(c);
308
309 if (c->desktop != DESKTOP_ALL && c->desktop != screen_desktop)
310 desk = screen_desktop_names[c->desktop];
311
312 title = c->iconic ? c->icon_title : c->title;
313
314 /* use the transient's parent's title/icon if we don't have one */
315 if (p != c && title[0] == '\0')
316 title = p->iconic ? p->icon_title : p->title;
317
318 if (desk)
319 ret = g_strdup_printf("%s [%s]", title, desk);
320 else
321 ret = g_strdup(title);
322
323 return ret;
324 }
325
326 static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
327 {
328 gint ml, mt, mr, mb;
329 gint l, t, r, b;
330 gint x, y, w, h;
331 Rect *screen_area = NULL;
332 gint i;
333 GList *it;
334 const ObFocusCyclePopupTarget *newtarget;
335 ObFocusCyclePopupMode mode = p->mode;
336 gint icons_per_row;
337 gint icon_rows;
338 gint textw, texth;
339 gint selected_pos;
340 gint last_scroll;
341
342 /* vars for icon mode */
343 gint icon_mode_textx;
344 gint icon_mode_texty;
345 gint icons_center_x;
346
347 /* vars for list mode */
348 gint list_mode_icon_column_w = HILITE_SIZE + OUTSIDE_BORDER;
349 gint up_arrow_x, down_arrow_x;
350 gint up_arrow_y, down_arrow_y;
351 gboolean showing_arrows = FALSE;
352
353 g_assert(mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS ||
354 mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST);
355
356 screen_area = screen_physical_area_primary(FALSE);
357
358 /* get the outside margins */
359 RrMargins(p->a_bg, &ml, &mt, &mr, &mb);
360
361 /* get our outside borders */
362 l = ml + OUTSIDE_BORDER;
363 r = mr + OUTSIDE_BORDER;
364 t = mt + OUTSIDE_BORDER;
365 b = mb + OUTSIDE_BORDER;
366
367 /* get the width from the text and keep it within limits */
368 w = l + r + p->maxtextw;
369 if (mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
370 /* when in list mode, there are icons down the side */
371 w += list_mode_icon_column_w;
372 w = MIN(w, MAX(screen_area->width/3, POPUP_WIDTH)); /* max width */
373 w = MAX(w, POPUP_WIDTH); /* min width */
374
375 /* get the text height */
376 texth = RrMinHeight(p->a_hilite_text);
377 if (mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
378 texth = MAX(MAX(texth, RrMinHeight(p->a_text)), HILITE_SIZE);
379 else
380 texth += TEXT_BORDER * 2;
381
382 if (mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS) {
383 /* how many icons will fit in that row? make the width fit that */
384 w -= l + r;
385 icons_per_row = (w + HILITE_SIZE - 1) / HILITE_SIZE;
386 w = icons_per_row * HILITE_SIZE + l + r;
387
388 /* how many rows do we need? */
389 icon_rows = (p->n_targets-1) / icons_per_row + 1;
390 } else {
391 /* in list mode, there is one column of icons.. */
392 icons_per_row = 1;
393 /* maximum is 80% of the screen height */
394 icon_rows = MIN(p->n_targets,
395 (4*screen_area->height/5) /* 80% of the screen */
396 /
397 MAX(HILITE_SIZE, texth)); /* height of each row */
398 /* but make sure there is always one */
399 icon_rows = MAX(icon_rows, 1);
400 }
401
402 /* get the text width */
403 textw = w - l - r;
404 if (mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
405 /* leave space on the side for the icons */
406 textw -= list_mode_icon_column_w;
407
408 if (!p->mapped)
409 /* reset the scrolling when the dialog is first shown */
410 p->scroll = 0;
411
412 /* find the height of the dialog */
413 h = t + b + (icon_rows * MAX(HILITE_SIZE, texth));
414 if (mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS)
415 /* in icon mode the text sits below the icons, so make some space */
416 h += OUTSIDE_BORDER + texth;
417
418 /* find the focused target */
419 newtarget = NULL;
420 for (i = 0, it = p->targets; it; ++i, it = g_list_next(it)) {
421 const ObFocusCyclePopupTarget *target = it->data;
422 if (target->client == c) {
423 /* save the target */
424 newtarget = target;
425 break;
426 }
427 }
428 selected_pos = i;
429 g_assert(newtarget != NULL);
430
431 /* scroll the list if needed */
432 last_scroll = p->scroll;
433 if (mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST) {
434 const gint top = p->scroll + SCROLL_MARGIN;
435 const gint bottom = p->scroll + icon_rows - SCROLL_MARGIN;
436 const gint min_scroll = 0;
437 const gint max_scroll = p->n_targets - icon_rows;
438
439 if (top - selected_pos >= 0) {
440 p->scroll -= top - selected_pos + 1;
441 p->scroll = MAX(p->scroll, min_scroll);
442 } else if (selected_pos - bottom >= 0) {
443 p->scroll += selected_pos - bottom + 1;
444 p->scroll = MIN(p->scroll, max_scroll);
445 }
446 }
447
448 /* show the scroll arrows when appropriate */
449 if (p->scroll && mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST) {
450 XMapWindow(obt_display, p->list_mode_up);
451 showing_arrows = TRUE;
452 } else
453 XUnmapWindow(obt_display, p->list_mode_up);
454
455 if (p->scroll < p->n_targets - icon_rows &&
456 mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
457 {
458 XMapWindow(obt_display, p->list_mode_down);
459 showing_arrows = TRUE;
460 } else
461 XUnmapWindow(obt_display, p->list_mode_down);
462
463 /* make space for the arrows */
464 if (showing_arrows)
465 h += ob_rr_theme->up_arrow_mask->height + OUTSIDE_BORDER
466 + ob_rr_theme->down_arrow_mask->height + OUTSIDE_BORDER;
467
468 /* center the icons if there is less than one row */
469 if (mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS && icon_rows == 1)
470 icons_center_x = (w - p->n_targets * HILITE_SIZE) / 2;
471 else
472 icons_center_x = 0;
473
474 if (mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS) {
475 /* get the position of the text */
476 icon_mode_textx = l;
477 icon_mode_texty = h - texth - b;
478 }
479
480 /* find the position for the popup (include the outer borders) */
481 x = screen_area->x + (screen_area->width -
482 (w + ob_rr_theme->obwidth * 2)) / 2;
483 y = screen_area->y + (screen_area->height -
484 (h + ob_rr_theme->obwidth * 2)) / 2;
485
486 if (!p->mapped) {
487 /* position the background but don't draw it */
488 XMoveResizeWindow(obt_display, p->bg, x, y, w, h);
489
490 if (mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS) {
491 /* position the text */
492 XMoveResizeWindow(obt_display, p->icon_mode_text,
493 icon_mode_textx, icon_mode_texty, textw, texth);
494 XMapWindow(obt_display, popup.icon_mode_text);
495 } else {
496 XUnmapWindow(obt_display, popup.icon_mode_text);
497
498 up_arrow_x = (w - ob_rr_theme->up_arrow_mask->width) / 2;
499 up_arrow_y = t;
500
501 down_arrow_x = (w - ob_rr_theme->down_arrow_mask->width) / 2;
502 down_arrow_y = h - b - ob_rr_theme->down_arrow_mask->height;
503
504 /* position the arrows */
505 XMoveResizeWindow(obt_display, p->list_mode_up,
506 up_arrow_x, up_arrow_y,
507 ob_rr_theme->up_arrow_mask->width,
508 ob_rr_theme->up_arrow_mask->height);
509 XMoveResizeWindow(obt_display, p->list_mode_down,
510 down_arrow_x, down_arrow_y,
511 ob_rr_theme->down_arrow_mask->width,
512 ob_rr_theme->down_arrow_mask->height);
513 }
514 }
515
516 /* * * draw everything * * */
517
518 /* draw the background */
519 if (!p->mapped)
520 RrPaint(p->a_bg, p->bg, w, h);
521
522 /* draw the scroll arrows */
523 if (!p->mapped && mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST) {
524 p->a_arrow->texture[0].data.mask.mask =
525 ob_rr_theme->up_arrow_mask;
526 p->a_arrow->surface.parent = p->a_bg;
527 p->a_arrow->surface.parentx = up_arrow_x;
528 p->a_arrow->surface.parenty = up_arrow_y;
529 RrPaint(p->a_arrow, p->list_mode_up,
530 ob_rr_theme->up_arrow_mask->width,
531 ob_rr_theme->up_arrow_mask->height);
532
533 p->a_arrow->texture[0].data.mask.mask =
534 ob_rr_theme->down_arrow_mask;
535 p->a_arrow->surface.parent = p->a_bg;
536 p->a_arrow->surface.parentx = down_arrow_x;
537 p->a_arrow->surface.parenty = down_arrow_y;
538 RrPaint(p->a_arrow, p->list_mode_down,
539 ob_rr_theme->down_arrow_mask->width,
540 ob_rr_theme->down_arrow_mask->height);
541 }
542
543 /* draw the icons and text */
544 for (i = 0, it = p->targets; it; ++i, it = g_list_next(it)) {
545 const ObFocusCyclePopupTarget *target = it->data;
546
547 /* have to redraw the targetted icon and last targetted icon
548 * to update the hilite */
549 if (!p->mapped || newtarget == target || p->last_target == target ||
550 last_scroll != p->scroll)
551 {
552 /* row and column start from 0 */
553 const gint row = i / icons_per_row - p->scroll;
554 const gint col = i % icons_per_row;
555 gint iconx, icony;
556 gint list_mode_textx, list_mode_texty;
557 RrAppearance *text;
558
559 /* find the coordinates for the icon */
560 iconx = icons_center_x + l + (col * HILITE_SIZE);
561 icony = t + (showing_arrows ? ob_rr_theme->up_arrow_mask->height
562 + OUTSIDE_BORDER
563 : 0)
564 + (row * MAX(texth, HILITE_SIZE))
565 + MAX(texth - HILITE_SIZE, 0) / 2;
566
567 /* find the dimensions of the text box */
568 list_mode_textx = iconx + HILITE_SIZE + TEXT_BORDER;
569 list_mode_texty = icony;
570
571 /* position the icon */
572 XMoveResizeWindow(obt_display, target->iconwin,
573 iconx, icony, HILITE_SIZE, HILITE_SIZE);
574
575 /* position the text */
576 if (mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
577 XMoveResizeWindow(obt_display, target->textwin,
578 list_mode_textx, list_mode_texty,
579 textw, texth);
580
581 /* show/hide the right windows */
582 if (row >= 0 && row < icon_rows) {
583 XMapWindow(obt_display, target->iconwin);
584 if (mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
585 XMapWindow(obt_display, target->textwin);
586 else
587 XUnmapWindow(obt_display, target->textwin);
588 } else {
589 XUnmapWindow(obt_display, target->textwin);
590 if (mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
591 XUnmapWindow(obt_display, target->iconwin);
592 else
593 XMapWindow(obt_display, target->iconwin);
594 }
595
596 /* get the icon from the client */
597 p->a_icon->texture[0].data.image.twidth = ICON_SIZE;
598 p->a_icon->texture[0].data.image.theight = ICON_SIZE;
599 p->a_icon->texture[0].data.image.tx = HILITE_OFFSET;
600 p->a_icon->texture[0].data.image.ty = HILITE_OFFSET;
601 p->a_icon->texture[0].data.image.alpha =
602 target->client->iconic ? OB_ICONIC_ALPHA : 0xff;
603 p->a_icon->texture[0].data.image.image = target->icon;
604
605 /* Draw the hilite? */
606 p->a_icon->texture[1].type = (target == newtarget) ?
607 RR_TEXTURE_RGBA : RR_TEXTURE_NONE;
608
609 /* draw the icon */
610 p->a_icon->surface.parentx = iconx;
611 p->a_icon->surface.parenty = icony;
612 RrPaint(p->a_icon, target->iconwin, HILITE_SIZE, HILITE_SIZE);
613
614 /* draw the text */
615 if (mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST ||
616 target == newtarget)
617 {
618 text = (target == newtarget) ? p->a_hilite_text : p->a_text;
619 text->texture[0].data.text.string = target->text;
620 text->surface.parentx =
621 mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS ?
622 icon_mode_textx : list_mode_textx;
623 text->surface.parenty =
624 mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS ?
625 icon_mode_texty : list_mode_texty;
626 RrPaint(text,
627 (mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS ?
628 p->icon_mode_text : target->textwin),
629 textw, texth);
630 }
631 }
632 }
633
634 p->last_target = newtarget;
635
636 g_free(screen_area);
637
638 XFlush(obt_display);
639 }
640
641 void focus_cycle_popup_show(ObClient *c, gboolean iconic_windows,
642 gboolean all_desktops, gboolean dock_windows,
643 gboolean desktop_windows,
644 ObFocusCyclePopupMode mode)
645 {
646 g_assert(c != NULL);
647
648 if (mode == OB_FOCUS_CYCLE_POPUP_MODE_NONE) {
649 focus_cycle_popup_hide();
650 return;
651 }
652
653 /* do this stuff only when the dialog is first showing */
654 if (!popup.mapped) {
655 popup_setup(&popup, TRUE, iconic_windows, all_desktops,
656 dock_windows, desktop_windows);
657 /* this is fixed once the dialog is shown */
658 popup.mode = mode;
659 }
660 g_assert(popup.targets != NULL);
661
662 popup_render(&popup, c);
663
664 if (!popup.mapped) {
665 /* show the dialog */
666 XMapWindow(obt_display, popup.bg);
667 XFlush(obt_display);
668 popup.mapped = TRUE;
669 screen_hide_desktop_popup();
670 }
671 }
672
673 void focus_cycle_popup_hide(void)
674 {
675 gulong ignore_start;
676
677 ignore_start = event_start_ignore_all_enters();
678
679 XUnmapWindow(obt_display, popup.bg);
680 XFlush(obt_display);
681
682 event_end_ignore_all_enters(ignore_start);
683
684 popup.mapped = FALSE;
685
686 while(popup.targets) {
687 ObFocusCyclePopupTarget *t = popup.targets->data;
688
689 RrImageUnref(t->icon);
690 g_free(t->text);
691 XDestroyWindow(obt_display, t->iconwin);
692 XDestroyWindow(obt_display, t->textwin);
693 g_free(t);
694
695 popup.targets = g_list_delete_link(popup.targets, popup.targets);
696 }
697 popup.n_targets = 0;
698 popup.last_target = NULL;
699 }
700
701 void focus_cycle_popup_single_show(struct _ObClient *c,
702 gboolean iconic_windows,
703 gboolean all_desktops,
704 gboolean dock_windows,
705 gboolean desktop_windows)
706 {
707 gchar *text;
708
709 g_assert(c != NULL);
710
711 /* do this stuff only when the dialog is first showing */
712 if (!popup.mapped) {
713 Rect *a;
714
715 popup_setup(&popup, FALSE, iconic_windows, all_desktops,
716 dock_windows, desktop_windows);
717 g_assert(popup.targets == NULL);
718
719 /* position the popup */
720 a = screen_physical_area_primary(FALSE);
721 icon_popup_position(single_popup, CenterGravity,
722 a->x + a->width / 2, a->y + a->height / 2);
723 icon_popup_height(single_popup, POPUP_HEIGHT);
724 icon_popup_min_width(single_popup, POPUP_WIDTH);
725 icon_popup_max_width(single_popup, MAX(a->width/3, POPUP_WIDTH));
726 icon_popup_text_width(single_popup, popup.maxtextw);
727 g_free(a);
728 }
729
730 text = popup_get_name(c);
731 icon_popup_show(single_popup, text, client_icon(c));
732 g_free(text);
733 screen_hide_desktop_popup();
734 }
735
736 void focus_cycle_popup_single_hide(void)
737 {
738 icon_popup_hide(single_popup);
739 }
740
741 gboolean focus_cycle_popup_is_showing(ObClient *client)
742 {
743 if (popup.mapped) {
744 GList *it;
745
746 for (it = popup.targets; it; it = g_list_next(it)) {
747 ObFocusCyclePopupTarget *t = it->data;
748 if (t->client == client)
749 return TRUE;
750 }
751 }
752 return FALSE;
753 }
This page took 0.070245 seconds and 3 git commands to generate.