2
* Copyright (C) 2010 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
19
#include "WindowManager.h"
25
unsigned long functions;
26
unsigned long decorations;
29
} MotifWmHints, MwmHints;
31
#define MWM_HINTS_FUNCTIONS (1L << 0)
32
#define MWM_HINTS_DECORATIONS (1L << 1)
33
#define _XA_MOTIF_WM_HINTS "_MOTIF_WM_HINTS"
35
static void gdk_window_set_mwm_hints (Window xid,
36
MotifWmHints *new_hints);
39
static WindowManager *window_manager = NULL;
41
class WindowManagerDummy : public WindowManager
43
bool IsWindowMaximized (guint32 xid)
48
bool IsWindowDecorated (guint32 xid)
53
void Restore (guint32 xid)
55
g_debug ("%s", G_STRFUNC);
58
void Minimize (guint32 xid)
60
g_debug ("%s", G_STRFUNC);
63
void Close (guint32 xid)
65
g_debug ("%s", G_STRFUNC);
70
WindowManager::Default ()
73
window_manager = new WindowManagerDummy ();
75
return window_manager;
79
WindowManager::SetDefault (WindowManager *manager)
81
window_manager = manager;
85
WindowManager::Decorate (guint32 xid)
87
MotifWmHints hints = { 0 };
89
hints.flags = MWM_HINTS_DECORATIONS;
90
hints.decorations = GDK_DECOR_ALL;
92
gdk_window_set_mwm_hints (xid, &hints);
96
WindowManager::Undecorate (guint32 xid)
98
MotifWmHints hints = { 0 };
100
hints.flags = MWM_HINTS_DECORATIONS;
101
hints.decorations = 0;
103
gdk_window_set_mwm_hints (xid, &hints);
110
gdk_window_set_mwm_hints (Window xid,
111
MotifWmHints *new_hints)
113
GdkDisplay *display = gdk_display_get_default();
114
Atom hints_atom = None;
116
MotifWmHints *hints = NULL;
122
g_return_if_fail (GDK_IS_DISPLAY (display));
124
hints_atom = gdk_x11_get_xatom_by_name_for_display (display,
127
gdk_error_trap_push ();
128
XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
130
hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
131
False, AnyPropertyType, &type, &format, &nitems,
132
&bytes_after, &data);
134
if (gdk_error_trap_pop ())
136
g_debug ("ERROR: Cannot set decorations");
140
if (type != hints_atom || !data)
144
hints = (MotifWmHints *)data;
146
if (new_hints->flags & MWM_HINTS_FUNCTIONS)
148
hints->flags |= MWM_HINTS_FUNCTIONS;
149
hints->functions = new_hints->functions;
151
if (new_hints->flags & MWM_HINTS_DECORATIONS)
153
hints->flags |= MWM_HINTS_DECORATIONS;
154
hints->decorations = new_hints->decorations;
158
gdk_error_trap_push ();
159
XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
161
hints_atom, hints_atom, 32, PropModeReplace,
162
(guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
164
if (gdk_error_trap_pop ())
166
g_debug ("ERROR: Setting decorations");