~alan-griffiths/compiz-core/Bug-931283

« back to all changes in this revision

Viewing changes to gnome/compiz-window-manager.c

  • Committer: David Reveman
  • Date: 2006-02-09 06:03:09 UTC
  • Revision ID: git-v1:9959c2b13ded64a5e66359a8097250dc9d87fc1c
Initial revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2005 Novell, Inc.
 
3
 *
 
4
 * Permission to use, copy, modify, distribute, and sell this software
 
5
 * and its documentation for any purpose is hereby granted without
 
6
 * fee, provided that the above copyright notice appear in all copies
 
7
 * and that both that copyright notice and this permission notice
 
8
 * appear in supporting documentation, and that the name of
 
9
 * Novell, Inc. not be used in advertising or publicity pertaining to
 
10
 * distribution of the software without specific, written prior permission.
 
11
 * Novell, Inc. makes no representations about the suitability of this
 
12
 * software for any purpose. It is provided "as is" without express or
 
13
 * implied warranty.
 
14
 *
 
15
 * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
16
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
 
17
 * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
18
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
 
19
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 
20
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 
21
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
22
 *
 
23
 * Author: David Reveman <davidr@novell.com>
 
24
 */
 
25
 
 
26
#include <config.h>
 
27
#include <sys/types.h>
 
28
#include <dirent.h>
 
29
#include <string.h>
 
30
#include <gconf/gconf-client.h>
 
31
 
 
32
#include "compiz-window-manager.h"
 
33
 
 
34
#define COMPIZ_CLICK_TO_FOCUS_KEY                            \
 
35
    "/apps/compiz/general/allscreens/options/click_to_focus"
 
36
 
 
37
#define COMPIZ_AUTORAISE_KEY                            \
 
38
    "/apps/compiz/general/allscreens/options/autoraise"
 
39
 
 
40
#define COMPIZ_AUTORAISE_DELAY_KEY                            \
 
41
    "/apps/compiz/general/allscreens/options/autoraise_delay"
 
42
 
 
43
#define COMPIZ_MOUSE_MOVE_KEY                            \
 
44
    "/apps/compiz/plugins/move/screen0/options/initiate"
 
45
 
 
46
#define COMPIZ_DOUBLE_CLICK_TITLEBAR_KEY                                   \
 
47
    "/apps/compiz/general/allscreens/options/action_double_click_titlebar"
 
48
 
 
49
enum {
 
50
    DOUBLE_CLICK_MAXIMIZE
 
51
};
 
52
 
 
53
static GnomeWindowManagerClass *parent_class;
 
54
 
 
55
struct _CompizWindowManagerPrivate {
 
56
    GConfClient *gconf;
 
57
    char        *mouse_modifier;
 
58
};
 
59
 
 
60
static void
 
61
value_changed (GConfClient *client,
 
62
               const gchar *key,
 
63
               GConfValue  *value,
 
64
               void        *data)
 
65
{
 
66
    CompizWindowManager *wm;
 
67
 
 
68
    wm = COMPIZ_WINDOW_MANAGER (data);
 
69
 
 
70
    gnome_window_manager_settings_changed (GNOME_WINDOW_MANAGER (wm));
 
71
}
 
72
 
 
73
/* this function is called when the shared lib is loaded */
 
74
GObject *
 
75
window_manager_new (int expected_interface_version)
 
76
{
 
77
    GObject *wm;
 
78
 
 
79
    if (expected_interface_version != GNOME_WINDOW_MANAGER_INTERFACE_VERSION)
 
80
    {
 
81
        g_warning ("Compiz window manager module wasn't compiled with the "
 
82
                   "current version of gnome-control-center");
 
83
        return NULL;
 
84
    }
 
85
 
 
86
    wm = g_object_new (compiz_window_manager_get_type (), NULL);
 
87
 
 
88
    return wm;
 
89
}
 
90
 
 
91
static void
 
92
compiz_change_settings (GnomeWindowManager    *wm,
 
93
                        const GnomeWMSettings *settings)
 
94
{
 
95
    CompizWindowManager *cwm;
 
96
 
 
97
    cwm = COMPIZ_WINDOW_MANAGER (wm);
 
98
 
 
99
    if (settings->flags & GNOME_WM_SETTING_MOUSE_FOCUS)
 
100
        gconf_client_set_bool (cwm->p->gconf,
 
101
                               COMPIZ_CLICK_TO_FOCUS_KEY,
 
102
                               settings->focus_follows_mouse == FALSE,
 
103
                               NULL);
 
104
 
 
105
     if (settings->flags & GNOME_WM_SETTING_AUTORAISE)
 
106
        gconf_client_set_bool (cwm->p->gconf,
 
107
                               COMPIZ_AUTORAISE_KEY,
 
108
                               settings->autoraise, NULL);
 
109
 
 
110
     if (settings->flags & GNOME_WM_SETTING_AUTORAISE_DELAY)
 
111
        gconf_client_set_int (cwm->p->gconf,
 
112
                              COMPIZ_AUTORAISE_DELAY_KEY,
 
113
                              settings->autoraise_delay, NULL);
 
114
 
 
115
    if (settings->flags & GNOME_WM_SETTING_MOUSE_MOVE_MODIFIER)
 
116
    {
 
117
        char *value;
 
118
 
 
119
        value = g_strdup_printf ("<%s>Button1", settings->mouse_move_modifier);
 
120
        gconf_client_set_string (cwm->p->gconf,
 
121
                                 COMPIZ_MOUSE_MOVE_KEY,
 
122
                                 value, NULL);
 
123
        g_free (value);
 
124
    }
 
125
 
 
126
/*
 
127
    if (settings->flags & GNOME_WM_SETTING_DOUBLE_CLICK_ACTION)
 
128
    {
 
129
        const char *action = NULL;
 
130
 
 
131
        switch (settings->double_click_action) {
 
132
        case DOUBLE_CLICK_SHADE:
 
133
            action = "toggle_shade";
 
134
            break;
 
135
        case DOUBLE_CLICK_MAXIMIZE:
 
136
            action = "toggle_maximize";
 
137
            break;
 
138
        }
 
139
 
 
140
        if (action)
 
141
            gconf_client_set_string (meta_wm->p->gconf,
 
142
                                     COMPIZ_DOUBLE_CLICK_TITLEBAR_KEY,
 
143
                                     action, NULL);
 
144
    }
 
145
*/
 
146
 
 
147
}
 
148
 
 
149
static void
 
150
compiz_get_settings (GnomeWindowManager *wm,
 
151
                     GnomeWMSettings    *settings)
 
152
{
 
153
    CompizWindowManager *cwm;
 
154
    int                 to_get;
 
155
 
 
156
    cwm = COMPIZ_WINDOW_MANAGER (wm);
 
157
 
 
158
    to_get = settings->flags;
 
159
    settings->flags = 0;
 
160
 
 
161
    if (to_get & GNOME_WM_SETTING_MOUSE_FOCUS)
 
162
    {
 
163
        settings->focus_follows_mouse =
 
164
            gconf_client_get_bool (cwm->p->gconf,
 
165
                                   COMPIZ_CLICK_TO_FOCUS_KEY, NULL) == FALSE;
 
166
 
 
167
        settings->flags |= GNOME_WM_SETTING_MOUSE_FOCUS;
 
168
    }
 
169
 
 
170
    if (to_get & GNOME_WM_SETTING_AUTORAISE)
 
171
    {
 
172
        settings->autoraise = FALSE;
 
173
 
 
174
        settings->autoraise = gconf_client_get_bool (cwm->p->gconf,
 
175
                                                     COMPIZ_AUTORAISE_KEY,
 
176
                                                     NULL);
 
177
 
 
178
        settings->flags |= GNOME_WM_SETTING_AUTORAISE;
 
179
    }
 
180
 
 
181
    if (to_get & GNOME_WM_SETTING_AUTORAISE_DELAY)
 
182
    {
 
183
        settings->autoraise_delay =
 
184
            gconf_client_get_int (cwm->p->gconf,
 
185
                                  COMPIZ_AUTORAISE_DELAY_KEY,
 
186
                                  NULL);
 
187
 
 
188
        settings->flags |= GNOME_WM_SETTING_AUTORAISE_DELAY;
 
189
    }
 
190
 
 
191
    if (to_get & GNOME_WM_SETTING_MOUSE_MOVE_MODIFIER)
 
192
    {
 
193
        const char *new;
 
194
        char       *str;
 
195
 
 
196
        str = gconf_client_get_string (cwm->p->gconf,
 
197
                                       COMPIZ_MOUSE_MOVE_KEY,
 
198
                                       NULL);
 
199
 
 
200
        if (str == NULL)
 
201
            str = g_strdup ("<Super>");
 
202
 
 
203
        if (strncmp (str, "<Super>", 7) == 0)
 
204
            new = "Super";
 
205
        else if (strncmp (str, "<Alt>", 5) == 0)
 
206
            new = "Alt";
 
207
        else if (strncmp (str, "<Meta>", 6) == 0)
 
208
            new = "Meta";
 
209
        else if (strncmp (str, "<Hyper>", 7) == 0)
 
210
            new = "Hyper";
 
211
        else if (strncmp (str, "<Control>", 9) == 0)
 
212
            new = "Control";
 
213
        else
 
214
            new = NULL;
 
215
 
 
216
        if (new && cwm->p->mouse_modifier &&
 
217
            strcmp (new, cwm->p->mouse_modifier) == 0)
 
218
        {
 
219
            /* unchanged */;
 
220
        }
 
221
        else
 
222
        {
 
223
            g_free (cwm->p->mouse_modifier);
 
224
            cwm->p->mouse_modifier = g_strdup (new ? new : "");
 
225
        }
 
226
 
 
227
        g_free (str);
 
228
 
 
229
        settings->mouse_move_modifier = cwm->p->mouse_modifier;
 
230
 
 
231
        settings->flags |= GNOME_WM_SETTING_MOUSE_MOVE_MODIFIER;
 
232
    }
 
233
 
 
234
    if (to_get & GNOME_WM_SETTING_DOUBLE_CLICK_ACTION)
 
235
    {
 
236
/*
 
237
        char *str;
 
238
 
 
239
        str = gconf_client_get_string (cwm->p->gconf,
 
240
                                       COMPIZ_DOUBLE_CLICK_TITLEBAR_KEY,
 
241
                                       NULL);
 
242
 
 
243
        if (str == NULL)
 
244
            str = g_strdup ("toggle_shade");
 
245
 
 
246
        if (strcmp (str, "toggle_shade") == 0)
 
247
            settings->double_click_action = DOUBLE_CLICK_SHADE;
 
248
        else if (strcmp (str, "toggle_maximize") == 0)
 
249
            settings->double_click_action = DOUBLE_CLICK_MAXIMIZE;
 
250
        else
 
251
            settings->double_click_action = DOUBLE_CLICK_SHADE;
 
252
 
 
253
        g_free (str);
 
254
 
 
255
        settings->flags |= GNOME_WM_SETTING_DOUBLE_CLICK_ACTION;
 
256
*/
 
257
    }
 
258
}
 
259
 
 
260
static int
 
261
compiz_get_settings_mask (GnomeWindowManager *wm)
 
262
{
 
263
    return
 
264
/*      GNOME_WM_SETTING_FONT                | */
 
265
        GNOME_WM_SETTING_MOUSE_FOCUS         |
 
266
        GNOME_WM_SETTING_AUTORAISE           |
 
267
        GNOME_WM_SETTING_AUTORAISE_DELAY     |
 
268
        GNOME_WM_SETTING_MOUSE_MOVE_MODIFIER |
 
269
/*      GNOME_WM_SETTING_THEME               | */
 
270
/*      GNOME_WM_SETTING_DOUBLE_CLICK_ACTION */ 0;
 
271
}
 
272
 
 
273
static GList *
 
274
compiz_get_theme_list (GnomeWindowManager *wm)
 
275
{
 
276
    return NULL;
 
277
}
 
278
 
 
279
static char *
 
280
compiz_get_user_theme_folder (GnomeWindowManager *wm)
 
281
{
 
282
    return NULL;
 
283
}
 
284
 
 
285
static void
 
286
compiz_get_double_click_actions (GnomeWindowManager             *wm,
 
287
                                 const GnomeWMDoubleClickAction **actions_p,
 
288
                                 int                            *n_actions_p)
 
289
{
 
290
    static GnomeWMDoubleClickAction actions[] = {
 
291
        { DOUBLE_CLICK_MAXIMIZE, "Maximize" }
 
292
    };
 
293
    static gboolean initialized = FALSE;
 
294
 
 
295
    if (!initialized)
 
296
    {
 
297
        int i = 0;
 
298
 
 
299
        initialized = TRUE;
 
300
        while (i < (int) G_N_ELEMENTS (actions))
 
301
        {
 
302
            g_assert (actions[i].number == i);
 
303
            actions[i].human_readable_name = actions[i].human_readable_name;
 
304
 
 
305
            ++i;
 
306
        }
 
307
    }
 
308
 
 
309
    *actions_p   = actions;
 
310
    *n_actions_p = (int) G_N_ELEMENTS (actions);
 
311
}
 
312
 
 
313
static void
 
314
compiz_window_manager_init (CompizWindowManager      *cwm,
 
315
                            CompizWindowManagerClass *class)
 
316
{
 
317
    cwm->p                 = g_new0 (CompizWindowManagerPrivate, 1);
 
318
    cwm->p->gconf          = gconf_client_get_default ();
 
319
    cwm->p->mouse_modifier = NULL;
 
320
 
 
321
    gconf_client_add_dir (cwm->p->gconf,
 
322
                          "/apps/compiz",
 
323
                          GCONF_CLIENT_PRELOAD_ONELEVEL,
 
324
                          NULL);
 
325
 
 
326
    g_signal_connect (G_OBJECT (cwm->p->gconf),
 
327
                      "value_changed",
 
328
                      G_CALLBACK (value_changed),
 
329
                      cwm);
 
330
}
 
331
 
 
332
static void
 
333
compiz_window_manager_finalize (GObject *object)
 
334
{
 
335
    CompizWindowManager *cwm;
 
336
 
 
337
    g_return_if_fail (object != NULL);
 
338
    g_return_if_fail (IS_COMPIZ_WINDOW_MANAGER (object));
 
339
 
 
340
    cwm = COMPIZ_WINDOW_MANAGER (object);
 
341
 
 
342
    g_signal_handlers_disconnect_by_func (G_OBJECT (cwm->p->gconf),
 
343
                                          G_CALLBACK (value_changed),
 
344
                                          cwm);
 
345
 
 
346
    g_object_unref (G_OBJECT (cwm->p->gconf));
 
347
    g_free (cwm->p);
 
348
 
 
349
    G_OBJECT_CLASS (parent_class)->finalize (object);
 
350
}
 
351
 
 
352
static void
 
353
compiz_window_manager_class_init (CompizWindowManagerClass *class)
 
354
{
 
355
    GObjectClass            *object_class;
 
356
    GnomeWindowManagerClass *wm_class;
 
357
 
 
358
    object_class = G_OBJECT_CLASS (class);
 
359
    wm_class     = GNOME_WINDOW_MANAGER_CLASS (class);
 
360
 
 
361
    object_class->finalize = compiz_window_manager_finalize;
 
362
 
 
363
    wm_class->change_settings          = compiz_change_settings;
 
364
    wm_class->get_settings             = compiz_get_settings;
 
365
    wm_class->get_settings_mask        = compiz_get_settings_mask;
 
366
    wm_class->get_theme_list           = compiz_get_theme_list;
 
367
    wm_class->get_user_theme_folder    = compiz_get_user_theme_folder;
 
368
    wm_class->get_double_click_actions = compiz_get_double_click_actions;
 
369
 
 
370
    parent_class = g_type_class_peek_parent (class);
 
371
}
 
372
 
 
373
GType
 
374
compiz_window_manager_get_type (void)
 
375
{
 
376
    static GType compiz_window_manager_type = 0;
 
377
 
 
378
    if (!compiz_window_manager_type)
 
379
    {
 
380
        static GTypeInfo compiz_window_manager_info = {
 
381
            sizeof (CompizWindowManagerClass),
 
382
            NULL,
 
383
            NULL,
 
384
            (GClassInitFunc) compiz_window_manager_class_init,
 
385
            NULL,
 
386
            NULL,
 
387
            sizeof (CompizWindowManager),
 
388
            0,
 
389
            (GInstanceInitFunc) compiz_window_manager_init,
 
390
            NULL
 
391
        };
 
392
 
 
393
        compiz_window_manager_type =
 
394
            g_type_register_static (gnome_window_manager_get_type (),
 
395
                                    "CompizWindowManager",
 
396
                                    &compiz_window_manager_info, 0);
 
397
    }
 
398
 
 
399
    return compiz_window_manager_type;
 
400
}