]> icculus.org git repositories - dana/openbox.git/blob - openbox/apps_menu.c
don't free the linkbase on reconfigure
[dana/openbox.git] / openbox / apps_menu.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    apps_menu.c for the Openbox window manager
4    Copyright (c) 2011        Dana Jansens
5
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.
10
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.
15
16    See the COPYING file for a copy of the GNU General Public License.
17 */
18
19 #include "openbox.h"
20 #include "menu.h"
21 #include "menuframe.h"
22 #include "screen.h"
23 #include "apps_menu.h"
24 #include "config.h"
25 #include "gettext.h"
26 #include "obt/linkbase.h"
27 #include "obt/link.h"
28 #include "obt/paths.h"
29
30 #include <glib.h>
31
32 #define MENU_NAME "apps-menu"
33
34 static ObMenu *apps_menu;
35 static ObtLinkBase *linkbase;
36 static gboolean dirty;
37
38 static void self_cleanup(ObMenu *menu, gpointer data)
39 {
40     menu_clear_entries(menu);
41 }
42
43 static gboolean self_update(ObMenuFrame *frame, gpointer data)
44 {
45     ObMenu *menu = frame->menu;
46     ObMenuEntry *e;
47
48     if (!dirty) return TRUE;  /* nothing has changed to be updated */
49
50 /*
51     menu_add_separator(menu, SEPARATOR, screen_desktop_names[desktop]);
52
53     gchar *title = g_strdup_printf("(%s)", c->icon_title);
54     e = menu_add_normal(menu, desktop, title, NULL, FALSE);
55     g_free(title);
56
57     if (config_menu_show_icons) {
58         e->data.normal.icon = client_icon(c);
59         RrImageRef(e->data.normal.icon);
60         e->data.normal.icon_alpha =
61             c->iconic ? OB_ICONIC_ALPHA : 0xff;
62     }
63
64     e->data.normal.data = link;
65 */
66
67     return TRUE; /* always show the menu */
68 }
69
70 static void menu_execute(ObMenuEntry *self, ObMenuFrame *f,
71                          ObClient *c, guint state, gpointer data)
72 {
73 #if 0
74     ObClient *t = self->data.normal.data;
75     if (t) { /* it's set to NULL if its destroyed */
76         gboolean here = state & ShiftMask;
77
78         client_activate(t, TRUE, here, TRUE, TRUE, TRUE);
79         /* if the window is omnipresent then we need to go to its
80            desktop */
81         if (!here && t->desktop == DESKTOP_ALL)
82             screen_set_desktop(self->id, FALSE);
83     }
84 #endif
85 }
86
87 void linkbase_update(ObtLinkBase *lb, gpointer data)
88 {
89     dirty = TRUE;
90 }
91
92 void apps_menu_startup(gboolean reconfig)
93 {
94     if (!reconfig) {
95         ObtPaths *paths;
96
97         paths = obt_paths_new();
98         /* XXX allow more environments, like GNOME or KDE, to be included */
99         linkbase = obt_linkbase_new(paths, ob_locale_msg,
100                                     OBT_LINK_ENV_OPENBOX);
101         obt_paths_unref(paths);
102     }
103
104     apps_menu = menu_new(MENU_NAME, _("Applications"), TRUE, NULL);
105     menu_set_update_func(apps_menu, self_update);
106     menu_set_cleanup_func(apps_menu, self_cleanup);
107     menu_set_execute_func(apps_menu, menu_execute);
108 }
109
110 void apps_menu_shutdown(gboolean reconfig)
111 {
112     if (!reconfig) {
113         obt_linkbase_unref(linkbase);
114         linkbase = NULL;
115     }
116
117     /* freed by the hash table */
118 }