2
* Copyright (C) 2008 Canonical Ltd
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU General Public
15
* License along with this library; if not, write to the
16
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
19
* Authored by Neil Jagdish Patel <neil.patel@canonical.com>
23
#include "launcher-wm.h"
25
#include "launcher-menu.h"
27
G_DEFINE_TYPE (LauncherWm, launcher_wm, G_TYPE_OBJECT);
29
#define LAUNCHER_WM_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj),\
33
struct _LauncherWmPrivate
47
static guint _wm_signals[LAST_SIGNAL] = { 0 };
50
on_active_window_changed (WnckScreen *screen,
51
WnckWindow *prev_window,
57
window = wnck_screen_get_active_window (screen);
59
if (!WNCK_IS_WINDOW (window))
61
g_signal_emit (wm, _wm_signals[HIDE_DECS], 0);
62
/*g_debug ("ACTIVE: Desktop\n");*/
66
type = wnck_window_get_window_type (window);
69
case WNCK_WINDOW_NORMAL:
71
case WNCK_WINDOW_DESKTOP:
72
case WNCK_WINDOW_DOCK:
73
g_signal_emit (wm, _wm_signals[HIDE_DECS], 0);
74
/*g_debug ("ACTIVE: Desktop\n");*/
80
g_signal_emit (wm, _wm_signals[SHOW_DECS], 0, window);
81
/*g_debug ("ACTIVE: %s\n", wnck_window_get_name (window));*/
85
on_window_opened (WnckScreen *screen, WnckWindow *window, LauncherWm *wm)
87
LauncherWmPrivate *priv;
92
g_return_if_fail (LAUNCHER_IS_WM (wm));
95
type = wnck_window_get_window_type (window);
98
case WNCK_WINDOW_NORMAL:
104
pid = wnck_window_get_pid (window);
106
list = launcher_menu_get_applications (launcher_menu_get_default ());
107
for (l = list; l; l = l->next)
109
if (pid == launcher_menu_application_get_pid (l->data))
111
launcher_menu_application_set_window (l->data, window);
113
g_hash_table_insert (priv->table, (gpointer)&pid, l->data);
120
on_window_closed (WnckScreen *screen, WnckWindow *window, LauncherWm *wm)
122
LauncherWmPrivate *priv;
123
LauncherMenuApplication *app = NULL;
127
g_return_if_fail (LAUNCHER_IS_WM (wm));
130
type = wnck_window_get_window_type (window);
133
case WNCK_WINDOW_NORMAL:
139
pid = wnck_window_get_pid (window);
141
app = g_hash_table_lookup (priv->table, (gconstpointer)&pid);
145
launcher_menu_application_set_pid (app, -1);
146
launcher_menu_application_set_window (app, NULL);
147
g_hash_table_remove (priv->table, (gconstpointer)&pid);
153
* Destroy the hashtable when the menu changes, as all its keys are invalid
156
on_menu_changed (LauncherMenu *menu, LauncherWm *wm)
158
g_return_if_fail (LAUNCHER_IS_WM (wm));
160
g_hash_table_unref (wm->priv->table);
161
wm->priv->table = NULL;
166
launcher_wm_class_init (LauncherWmClass *klass)
168
GObjectClass *obj_class = G_OBJECT_CLASS (klass);
170
_wm_signals[SHOW_DECS] =
171
g_signal_new ("show-windec",
172
G_OBJECT_CLASS_TYPE (obj_class),
174
G_STRUCT_OFFSET (LauncherWmClass, show_windec),
176
g_cclosure_marshal_VOID__OBJECT,
178
1, WNCK_TYPE_WINDOW);
180
_wm_signals[HIDE_DECS] =
181
g_signal_new ("hide-windec",
182
G_OBJECT_CLASS_TYPE (obj_class),
184
G_STRUCT_OFFSET (LauncherWmClass, hide_windec),
186
g_cclosure_marshal_VOID__VOID,
189
g_type_class_add_private (obj_class, sizeof (LauncherWmPrivate));
193
launcher_wm_init (LauncherWm *wm)
195
LauncherWmPrivate *priv;
197
priv = wm->priv = LAUNCHER_WM_GET_PRIVATE (wm);
199
priv->screen = wnck_screen_get_default ();
201
priv->table = g_hash_table_new (g_int_hash, g_direct_equal);
203
g_signal_connect (priv->screen, "active-window-changed",
204
G_CALLBACK (on_active_window_changed), (gpointer)wm);
205
g_signal_connect (priv->screen, "window-opened",
206
G_CALLBACK (on_window_opened), (gpointer)wm);
207
g_signal_connect (priv->screen, "window-closed",
208
G_CALLBACK (on_window_closed), (gpointer)wm);
210
g_signal_connect (launcher_menu_get_default (), "menu-changed",
211
G_CALLBACK (on_menu_changed), wm);
215
launcher_wm_get_default (void)
218
static LauncherWm *wm = NULL;
221
wm = g_object_new (LAUNCHER_TYPE_WM,