]> icculus.org git repositories - mikachu/openbox.git/blob - openbox/client_list_combined_menu.c
a combined client_list_menu, use as client-list-combined-menu in your rc.xml. needs...
[mikachu/openbox.git] / 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        Ben 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 "action.h"
24 #include "screen.h"
25 #include "client.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 ObMenu *combined_menu;
35
36 static void self_update(ObMenuFrame *frame, gpointer data)
37 {
38     ObMenu *menu = frame->menu;
39     GList *it;
40     gint i;
41     gboolean icons = FALSE;
42     guint desktop;
43
44     menu_clear_entries(menu);
45
46     for (desktop = 0; desktop < screen_num_desktops; desktop++) {
47         for (it = focus_order[desktop], i = 0; it; it = g_list_next(it), ++i) {
48             ObClient *c = it->data;
49             if (client_normal(c) && (!c->skip_taskbar || c->iconic)) {
50                 GSList *acts = NULL;
51                 ObAction* act;
52                 ObMenuEntry *e;
53                 const ObClientIcon *icon;
54
55                 if (!icons && c->iconic) {
56                     icons = TRUE;
57                     menu_add_separator(menu, -1);
58                 }
59
60                 act = action_from_string("Activate",
61                         OB_USER_ACTION_MENU_SELECTION);
62                 act->data.activate.any.c = c;
63                 acts = g_slist_append(acts, act);
64                 act = action_from_string("Desktop",
65                         OB_USER_ACTION_MENU_SELECTION);
66                 act->data.desktop.desk = desktop;
67                 acts = g_slist_append(acts, act);
68                 e = menu_add_normal(menu, i,
69                         (c->iconic ? c->icon_title : c->title), acts);
70
71                 if (config_menu_client_list_icons
72                         && (icon = client_icon(c, 32, 32))) {
73                     e->data.normal.icon_width = icon->width;
74                     e->data.normal.icon_height = icon->height;
75                     e->data.normal.icon_data = icon->data;
76                 }
77             }
78         }
79         menu_add_separator(menu, -1);
80         menu_add_separator(menu, -1);
81         icons = FALSE;
82     }
83 }
84
85 /* executes it using the client in the actions, since we set that
86    when we make the actions! */
87 static void desk_menu_execute(ObMenuEntry *self, guint state, gpointer data)
88 {
89     ObAction *a;
90
91     if (self->data.normal.actions) {
92         a = self->data.normal.actions->data;
93         action_run(self->data.normal.actions, a->data.any.c, state);
94     }
95 }
96
97 static void client_dest(ObClient *client, gpointer data)
98 {
99     /* This concise function removes all references to a closed
100      * client in the client_list_menu, so we don't have to check
101      * in client.c */
102     GList *eit;
103     for (eit = combined_menu->entries; eit; eit = g_list_next(eit)) {
104         ObMenuEntry *meit = eit->data;
105         if (meit->type == OB_MENU_ENTRY_TYPE_NORMAL) {
106             ObAction *a = meit->data.normal.actions->data;
107             ObClient *c = a->data.any.c;
108             if (c == client)
109                 a->data.any.c = NULL;
110         }
111     }
112 }
113
114 void client_list_combined_menu_startup(gboolean reconfig)
115 {
116     if (!reconfig)
117         client_add_destructor(client_dest, NULL);
118
119     combined_menu = menu_new(MENU_NAME, _("Windows"), NULL);
120     menu_set_update_func(combined_menu, self_update);
121 }
122
123 void client_list_combined_menu_shutdown(gboolean reconfig)
124 {
125     if (!reconfig)
126         client_remove_destructor(client_dest);
127 }