~ubuntu-branches/ubuntu/precise/xfwm4/precise-updates

« back to all changes in this revision

Viewing changes to src/screen.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-11-10 07:40:26 UTC
  • mfrom: (1.1.20 upstream)
  • Revision ID: james.westby@ubuntu.com-20081110074026-xo3f144nja3wl7kz
Tags: 4.4.3-0ubuntu1
* Merge with Debian Xfce UNRELEASED, remaining Ubuntu changes
  - debian/xfwm4.1: update bug reporting address (LP instead of Debian BTS).
  - debian/rules: keep the .desktop installed, but add "NoDisplay=true" to hide
    them by default

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*      $Id: screen.c 24291 2007-01-07 20:23:21Z olivier $
 
1
/*      $Id: screen.c 28384 2008-10-23 17:18:16Z olivier $
2
2
 
3
3
        This program is free software; you can redistribute it and/or modify
4
4
        it under the terms of the GNU General Public License as published by
43
43
 
44
44
#include "display.h"
45
45
#include "screen.h"
46
 
#include "mywindow.h"
 
46
#include "misc.h"
47
47
#include "mywindow.h"
48
48
#include "compositor.h"
49
49
 
 
50
gboolean
 
51
myScreenCheckWMAtom (ScreenInfo *screen_info, Atom atom)
 
52
{
 
53
    gchar selection[32];
 
54
    Atom wm_sn_atom;
 
55
 
 
56
    TRACE ("entering myScreenCheckWMAtom");
 
57
    g_snprintf (selection, sizeof (selection), "WM_S%d", screen_info->screen);
 
58
    wm_sn_atom = XInternAtom (myScreenGetXDisplay (screen_info), selection, FALSE);
 
59
 
 
60
    return (atom == wm_sn_atom);
 
61
}
 
62
 
 
63
static gboolean
 
64
myScreenSetWMAtom (ScreenInfo *screen_info, gboolean replace_wm)
 
65
{
 
66
    gchar selection[32];
 
67
    gulong wait, timeout;
 
68
    DisplayInfo *display_info;
 
69
    XSetWindowAttributes attrs;
 
70
    Window current_wm;
 
71
    XEvent event;
 
72
    Atom wm_sn_atom;
 
73
 
 
74
    g_return_val_if_fail (screen_info, FALSE);
 
75
    g_return_val_if_fail (screen_info->display_info, FALSE);
 
76
 
 
77
    TRACE ("entering myScreenReplaceWM");
 
78
 
 
79
    display_info = screen_info->display_info;
 
80
    g_snprintf (selection, sizeof (selection), "WM_S%d", screen_info->screen);
 
81
    wm_sn_atom = XInternAtom (display_info->dpy, selection, FALSE);
 
82
 
 
83
    current_wm = XGetSelectionOwner (display_info->dpy, wm_sn_atom);
 
84
    if (current_wm)
 
85
    {
 
86
        if (!replace_wm)
 
87
        {
 
88
            g_message (_("To replace the window manager, try with \"--replace\"\n"));
 
89
            return FALSE;
 
90
        }
 
91
        gdk_error_trap_push ();
 
92
        attrs.event_mask = StructureNotifyMask;
 
93
        XChangeWindowAttributes (display_info->dpy, current_wm, CWEventMask, &attrs);
 
94
        if (gdk_error_trap_pop ())
 
95
        {
 
96
            current_wm = None;
 
97
        }
 
98
    }
 
99
 
 
100
    if (!setXAtomManagerOwner (display_info, wm_sn_atom, screen_info->xroot, screen_info->xfwm4_win))
 
101
    {
 
102
        g_warning (_("Cannot acquire window manager selection on screen %d\n"), screen_info->screen);
 
103
        return FALSE;
 
104
    }
 
105
 
 
106
    /* Waiting for previous window manager to exit */
 
107
    if (current_wm)
 
108
    {
 
109
        wait = 0;
 
110
        timeout = 10 * G_USEC_PER_SEC;
 
111
        while (wait < timeout)
 
112
        {
 
113
            if (XCheckWindowEvent (display_info->dpy, current_wm, StructureNotifyMask, &event) && (event.type == DestroyNotify))
 
114
            {
 
115
                break;
 
116
            }
 
117
            g_usleep(G_USEC_PER_SEC / 10);
 
118
            wait += G_USEC_PER_SEC / 10;
 
119
        }
 
120
 
 
121
        if (wait >= timeout)
 
122
        {
 
123
            g_warning(_("Previous window manager on screen %d is not exiting"), screen_info->screen);
 
124
            return FALSE;
 
125
        }
 
126
    }
 
127
    return TRUE;
 
128
}
 
129
 
50
130
ScreenInfo *
51
 
myScreenInit (DisplayInfo *display_info, GdkScreen *gscr, unsigned long event_mask)
 
131
myScreenInit (DisplayInfo *display_info, GdkScreen *gscr, unsigned long event_mask, gboolean replace_wm)
52
132
{
53
 
    gchar selection[32];
54
133
    ScreenInfo *screen_info;
55
134
    GdkWindow *event_win;
56
135
    PangoLayout *layout;
57
 
    Atom wm_sn_atom;
58
136
    long desktop_visible;
59
137
    int i;
60
138
 
88
166
    pango_layout_get_pixel_extents (layout, NULL, NULL);
89
167
    g_object_unref (G_OBJECT (layout));
90
168
 
91
 
    event_win = eventFilterAddWin (gscr, event_mask);
92
 
    if (!event_win)
93
 
    {
94
 
        gtk_widget_destroy (screen_info->gtk_win);
95
 
        g_free (screen_info);
96
 
        return NULL;
97
 
    }
98
 
    gdk_window_set_user_data (event_win, screen_info->gtk_win);
99
 
 
100
169
    screen_info->xscreen = gdk_x11_screen_get_xscreen (gscr);
101
170
    screen_info->xroot = (Window) GDK_DRAWABLE_XID(gdk_screen_get_root_window (gscr));
102
171
    screen_info->screen = gdk_screen_get_number (gscr);
105
174
    screen_info->width = WidthOfScreen (screen_info->xscreen);
106
175
    screen_info->height = HeightOfScreen (screen_info->xscreen);
107
176
    screen_info->visual = DefaultVisual (display_info->dpy, screen_info->screen);
 
177
 
 
178
    screen_info->xfwm4_win = GDK_WINDOW_XWINDOW (screen_info->gtk_win->window);
 
179
    if (!myScreenSetWMAtom (screen_info, replace_wm))
 
180
    {
 
181
        gtk_widget_destroy (screen_info->gtk_win);
 
182
        g_free (screen_info);
 
183
        return NULL;
 
184
    }
 
185
 
 
186
    event_win = eventFilterAddWin (gscr, event_mask);
 
187
    if (!event_win)
 
188
    {
 
189
        gtk_widget_destroy (screen_info->gtk_win);
 
190
        g_free (screen_info);
 
191
        return NULL;
 
192
    }
 
193
    gdk_window_set_user_data (event_win, screen_info->gtk_win);
 
194
 
108
195
    screen_info->current_ws = 0;
109
196
    screen_info->previous_ws = 0;
110
197
    screen_info->current_ws = 0;
178
265
                    EnterWindowMask,
179
266
                    TRUE);
180
267
 
181
 
    screen_info->xfwm4_win = GDK_WINDOW_XWINDOW (screen_info->gtk_win->window);
182
 
 
183
268
#ifdef ENABLE_KDE_SYSTRAY_PROXY
184
269
    g_snprintf (selection, sizeof (selection), "_NET_SYSTEM_TRAY_S%d", screen_info->screen);
185
270
    screen_info->net_system_tray_selection = XInternAtom (display_info->dpy, selection, FALSE);
186
271
    screen_info->systray = getSystrayWindow (display_info, screen_info->net_system_tray_selection);
187
272
#endif
188
273
 
189
 
    g_snprintf (selection, sizeof (selection), "WM_S%d", screen_info->screen);
190
 
    wm_sn_atom = XInternAtom (display_info->dpy, selection, FALSE);
191
 
    XSetSelectionOwner (display_info->dpy, wm_sn_atom, screen_info->xfwm4_win, CurrentTime);
192
 
 
193
274
    screen_info->box_gc = None;
194
275
    screen_info->black_gc = NULL;
195
276
    screen_info->white_gc = NULL;
304
385
}
305
386
 
306
387
gboolean
307
 
myScreenGrabKeyboard (ScreenInfo *screen_info, Time time)
 
388
myScreenGrabKeyboard (ScreenInfo *screen_info, guint32 time)
308
389
{
309
390
    gboolean grab;
310
391
 
319
400
                               screen_info->xfwm4_win,
320
401
                               FALSE,
321
402
                               GrabModeAsync, GrabModeAsync,
322
 
                               time) == GrabSuccess);
 
403
                               (Time) time) == GrabSuccess);
323
404
    }
324
405
    screen_info->key_grabs++;
325
406
    TRACE ("global key grabs %i", screen_info->key_grabs);
328
409
}
329
410
 
330
411
gboolean
331
 
myScreenCheckWMAtom (ScreenInfo *screen_info, Atom atom)
332
 
{
333
 
    gchar selection[32];
334
 
    Atom wm_sn_atom;
335
 
 
336
 
    g_snprintf (selection, sizeof (selection), "WM_S%d", screen_info->screen);
337
 
    wm_sn_atom = XInternAtom (myScreenGetXDisplay (screen_info), selection, FALSE);
338
 
 
339
 
    return (atom == wm_sn_atom);
340
 
}
341
 
 
342
 
gboolean
343
 
myScreenGrabPointer (ScreenInfo *screen_info, unsigned int event_mask, Cursor cursor, Time time)
 
412
myScreenGrabPointer (ScreenInfo *screen_info, unsigned int event_mask, Cursor cursor, guint32 time)
344
413
{
345
414
    gboolean grab;
346
415
 
356
425
                              GrabModeAsync, GrabModeAsync,
357
426
                              screen_info->xroot,
358
427
                              cursor,
359
 
                              time) == GrabSuccess);
 
428
                              (Time) time) == GrabSuccess);
360
429
    }
361
430
    screen_info->pointer_grabs++;
362
431
    TRACE ("global pointer grabs %i", screen_info->pointer_grabs);