]> Dogcows Code - chaz/openbox/blob - openbox/client_list_combined_menu.c
Merge branch 'backport' into work
[chaz/openbox] / openbox / client_list_combined_menu.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3 client_list_menu.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 "openbox.h"
21 #include "menu.h"
22 #include "menuframe.h"
23 #include "screen.h"
24 #include "client.h"
25 #include "client_list_combined_menu.h"
26 #include "focus.h"
27 #include "config.h"
28 #include "gettext.h"
29
30 #include <glib.h>
31
32 #define MENU_NAME "client-list-combined-menu"
33
34 static ObMenu *combined_menu;
35
36 #define SEPARATOR -1
37 #define ADD_DESKTOP -2
38 #define REMOVE_DESKTOP -3
39
40 static gboolean self_update(ObMenuFrame *frame, gpointer data)
41 {
42 ObMenu *menu = frame->menu;
43 ObMenuEntry *e;
44 GList *it;
45 guint desktop;
46
47 menu_clear_entries(menu);
48
49 for (desktop = 0; desktop < screen_num_desktops; desktop++) {
50 gboolean empty = TRUE;
51 gboolean onlyiconic = TRUE;
52
53 menu_add_separator(menu, SEPARATOR, screen_desktop_names[desktop]);
54 for (it = focus_order; it; it = g_list_next(it)) {
55 ObClient *c = it->data;
56 if (client_normal(c) && (!c->skip_taskbar || c->iconic) &&
57 (c->desktop == desktop || c->desktop == DESKTOP_ALL))
58 {
59 const ObClientIcon *icon;
60
61 empty = FALSE;
62
63 if (c->iconic) {
64 gchar *title = g_strdup_printf("(%s)", c->icon_title);
65 e = menu_add_normal(menu, desktop, title, NULL, FALSE);
66 g_free(title);
67 } else {
68 onlyiconic = FALSE;
69 e = menu_add_normal(menu, desktop, c->title, NULL, FALSE);
70 }
71
72 if (config_menu_client_list_icons
73 && (icon = client_icon(c, 32, 32))) {
74 e->data.normal.icon_width = icon->width;
75 e->data.normal.icon_height = icon->height;
76 e->data.normal.icon_data = icon->data;
77 e->data.normal.icon_alpha =
78 c->iconic ? OB_ICONIC_ALPHA : 0xff;
79 }
80
81 e->data.normal.data = c;
82 }
83 }
84
85 if (empty || onlyiconic) {
86 /* no entries or only iconified windows, so add a
87 * way to go to this desktop without uniconifying a window */
88 if (!empty)
89 menu_add_separator(menu, SEPARATOR, NULL);
90
91 e = menu_add_normal(menu, desktop, _("Go there..."), NULL, TRUE);
92 if (desktop == screen_desktop)
93 e->data.normal.enabled = FALSE;
94 }
95 }
96
97 if (config_menu_manage_desktops) {
98 menu_add_separator(menu, SEPARATOR, _("Manage desktops"));
99 menu_add_normal(menu, ADD_DESKTOP, _("_Add new desktop"), NULL, TRUE);
100 menu_add_normal(menu, REMOVE_DESKTOP, _("_Remove last desktop"),
101 NULL, TRUE);
102 }
103
104 return TRUE; /* always show the menu */
105 }
106
107 static void menu_execute(ObMenuEntry *self, ObMenuFrame *f,
108 ObClient *c, guint state, gpointer data)
109 {
110 if (self->id == ADD_DESKTOP) {
111 screen_add_desktop(FALSE);
112 menu_frame_hide_all();
113 }
114 else if (self->id == REMOVE_DESKTOP) {
115 screen_remove_desktop(FALSE);
116 menu_frame_hide_all();
117 }
118 else {
119 ObClient *t = self->data.normal.data;
120 if (t) { /* it's set to NULL if its destroyed */
121 client_activate(t, FALSE, TRUE, TRUE, TRUE);
122 /* if the window is omnipresent then we need to go to its
123 desktop */
124 if (t->desktop == DESKTOP_ALL)
125 screen_set_desktop(self->id, FALSE);
126 }
127 else
128 screen_set_desktop(self->id, TRUE);
129 }
130 }
131
132 static void client_dest(ObClient *client, gpointer data)
133 {
134 /* This concise function removes all references to a closed
135 * client in the client_list_menu, so we don't have to check
136 * in client.c */
137 GList *eit;
138 for (eit = combined_menu->entries; eit; eit = g_list_next(eit)) {
139 ObMenuEntry *meit = eit->data;
140 if (meit->type == OB_MENU_ENTRY_TYPE_NORMAL &&
141 meit->data.normal.data == client)
142 {
143 meit->data.normal.data = NULL;
144 }
145 }
146 }
147
148 void client_list_combined_menu_startup(gboolean reconfig)
149 {
150 if (!reconfig)
151 client_add_destroy_notify(client_dest, NULL);
152
153 combined_menu = menu_new(MENU_NAME, _("Windows"), TRUE, NULL);
154 menu_set_update_func(combined_menu, self_update);
155 menu_set_execute_func(combined_menu, menu_execute);
156 }
157
158 void client_list_combined_menu_shutdown(gboolean reconfig)
159 {
160 if (!reconfig)
161 client_remove_destroy_notify(client_dest);
162 }
This page took 0.043221 seconds and 5 git commands to generate.