summaryrefslogtreecommitdiff
path: root/src
diff options
authorNeil Jagdish Patel <neil.patel@canonical.com>2010-12-16 22:12:54 +0000
committerNeil Jagdish Patel <neil.patel@canonical.com>2010-12-16 22:12:54 +0000
commiteffe86705e3335fbea3a2ca7af2ce6b0a9ddd718 (patch)
tree445d9da3616744b8a095d8d61bc0a4cff90187d1 /src
parent321915169f8317dbbacc0065ffc05261b3d4a907 (diff)
Enable support for decorating/undecorating
(bzr r669.3.23)
Diffstat (limited to 'src')
-rw-r--r--src/PanelMenuView.cpp12
-rw-r--r--src/WindowManager.cpp107
-rw-r--r--src/WindowManager.h3
3 files changed, 112 insertions, 10 deletions
diff --git a/src/PanelMenuView.cpp b/src/PanelMenuView.cpp
index fcb6e2a03..2fd8898c9 100644
--- a/src/PanelMenuView.cpp
+++ b/src/PanelMenuView.cpp
@@ -490,11 +490,7 @@ PanelMenuView::OnWindowMaximized (guint xid)
if (_decor_map[xid])
{
- g_debug ("Undecorate");
- }
- else
- {
- g_debug ("Already undecorated, leaving");
+ WindowManager::Default ()->Undecorate (xid);
}
_is_maximized = true;
@@ -516,11 +512,7 @@ PanelMenuView::OnWindowRestored (guint xid)
if (_decor_map[xid])
{
- g_debug ("Redecorating<F2>");
- }
- else
- {
- g_debug ("Was already undecorated, leaving");
+ WindowManager::Default ()->Decorate (xid);
}
Refresh ();
diff --git a/src/WindowManager.cpp b/src/WindowManager.cpp
index d2456158b..b7e0e26b8 100644
--- a/src/WindowManager.cpp
+++ b/src/WindowManager.cpp
@@ -18,6 +18,24 @@
#include "WindowManager.h"
+#include <gdk/gdkx.h>
+
+typedef struct {
+ unsigned long flags;
+ unsigned long functions;
+ unsigned long decorations;
+ long input_mode;
+ unsigned long status;
+} MotifWmHints, MwmHints;
+
+#define MWM_HINTS_FUNCTIONS (1L << 0)
+#define MWM_HINTS_DECORATIONS (1L << 1)
+#define _XA_MOTIF_WM_HINTS "_MOTIF_WM_HINTS"
+
+static void gdk_window_set_mwm_hints (Window xid,
+ MotifWmHints *new_hints);
+
+
static WindowManager *window_manager = NULL;
class WindowManagerDummy : public WindowManager
@@ -62,3 +80,92 @@ WindowManager::SetDefault (WindowManager *manager)
{
window_manager = manager;
}
+
+void
+WindowManager::Decorate (guint32 xid)
+{
+ MotifWmHints hints = { 0 };
+
+ hints.flags = MWM_HINTS_DECORATIONS;
+ hints.decorations = GDK_DECOR_ALL;
+
+ gdk_window_set_mwm_hints (xid, &hints);
+}
+
+void
+WindowManager::Undecorate (guint32 xid)
+{
+ MotifWmHints hints = { 0 };
+
+ hints.flags = MWM_HINTS_DECORATIONS;
+ hints.decorations = 0;
+
+ gdk_window_set_mwm_hints (xid, &hints);
+}
+
+/*
+ * Copied over C code
+ */
+static void
+gdk_window_set_mwm_hints (Window xid,
+ MotifWmHints *new_hints)
+{
+ GdkDisplay *display = gdk_display_get_default();
+ Atom hints_atom = None;
+ guchar *data = NULL;
+ MotifWmHints *hints = NULL;
+ Atom type = None;
+ gint format;
+ gulong nitems;
+ gulong bytes_after;
+
+ g_return_if_fail (GDK_IS_DISPLAY (display));
+
+ hints_atom = gdk_x11_get_xatom_by_name_for_display (display,
+ _XA_MOTIF_WM_HINTS);
+
+ gdk_error_trap_push ();
+ XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
+ xid,
+ hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
+ False, AnyPropertyType, &type, &format, &nitems,
+ &bytes_after, &data);
+ gdk_flush ();
+ if (gdk_error_trap_pop ())
+ {
+ g_debug ("ERROR: Cannot set decorations");
+ return;
+ }
+
+ if (type != hints_atom || !data)
+ hints = new_hints;
+ else
+ {
+ hints = (MotifWmHints *)data;
+
+ if (new_hints->flags & MWM_HINTS_FUNCTIONS)
+ {
+ hints->flags |= MWM_HINTS_FUNCTIONS;
+ hints->functions = new_hints->functions;
+ }
+ if (new_hints->flags & MWM_HINTS_DECORATIONS)
+ {
+ hints->flags |= MWM_HINTS_DECORATIONS;
+ hints->decorations = new_hints->decorations;
+ }
+ }
+
+ gdk_error_trap_push ();
+ XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
+ xid,
+ hints_atom, hints_atom, 32, PropModeReplace,
+ (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
+ gdk_flush ();
+ if (gdk_error_trap_pop ())
+ {
+ g_debug ("ERROR: Setting decorations");
+ }
+
+ if (data)
+ XFree (data);
+}
diff --git a/src/WindowManager.h b/src/WindowManager.h
index 94a594f7a..e8df76330 100644
--- a/src/WindowManager.h
+++ b/src/WindowManager.h
@@ -36,6 +36,9 @@ public:
virtual void Minimize (guint32 xid) = 0;
virtual void Close (guint32 xid) = 0;
+ virtual void Decorate (guint32 xid);
+ virtual void Undecorate (guint32 xid);
+
// Signals
sigc::signal<void, guint32> window_mapped;
sigc::signal<void, guint32> window_unmapped;