~canonical-dx-team/unity/unity.fix-ql-losing-focus

« back to all changes in this revision

Viewing changes to src/WindowManager.cpp

  • Committer: Michael Terry
  • Date: 2010-12-17 14:07:11 UTC
  • mfrom: (724 unity)
  • mto: This revision was merged to the branch mainline in revision 743.
  • Revision ID: mike@mterry.name-20101217140711-qlij3bxdjuq1xoph
mergeĀ fromĀ upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2010 Canonical Ltd
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
 
17
 */
 
18
 
 
19
#include "WindowManager.h"
 
20
 
 
21
#include <gdk/gdkx.h>
 
22
 
 
23
typedef struct {
 
24
    unsigned long flags;
 
25
    unsigned long functions;
 
26
    unsigned long decorations;
 
27
    long input_mode;
 
28
    unsigned long status;
 
29
} MotifWmHints, MwmHints;
 
30
 
 
31
#define MWM_HINTS_FUNCTIONS     (1L << 0)
 
32
#define MWM_HINTS_DECORATIONS   (1L << 1)
 
33
#define _XA_MOTIF_WM_HINTS              "_MOTIF_WM_HINTS"
 
34
 
 
35
static void gdk_window_set_mwm_hints (Window        xid,
 
36
                                      MotifWmHints *new_hints);
 
37
 
 
38
 
 
39
static WindowManager *window_manager = NULL;
 
40
 
 
41
class WindowManagerDummy : public WindowManager
 
42
{
 
43
  bool IsWindowMaximized (guint32 xid)
 
44
  {
 
45
    return false;
 
46
  }
 
47
 
 
48
  bool IsWindowDecorated (guint32 xid)
 
49
  {
 
50
    return true;
 
51
  }
 
52
 
 
53
  void Restore (guint32 xid)
 
54
  {
 
55
    g_debug ("%s", G_STRFUNC);
 
56
  }
 
57
 
 
58
  void Minimize (guint32 xid)
 
59
  {
 
60
    g_debug ("%s", G_STRFUNC);
 
61
  }
 
62
 
 
63
 void Close (guint32 xid)
 
64
  {
 
65
    g_debug ("%s", G_STRFUNC);
 
66
  }
 
67
};
 
68
 
 
69
WindowManager *
 
70
WindowManager::Default ()
 
71
{
 
72
  if (!window_manager)
 
73
    window_manager = new WindowManagerDummy ();
 
74
 
 
75
  return window_manager;
 
76
}
 
77
 
 
78
void
 
79
WindowManager::SetDefault (WindowManager *manager)
 
80
{
 
81
  window_manager = manager;
 
82
}
 
83
 
 
84
void
 
85
WindowManager::Decorate (guint32 xid)
 
86
{
 
87
  MotifWmHints hints = { 0 };
 
88
    
 
89
  hints.flags = MWM_HINTS_DECORATIONS;
 
90
  hints.decorations = GDK_DECOR_ALL;
 
91
 
 
92
  gdk_window_set_mwm_hints (xid, &hints);
 
93
}
 
94
 
 
95
void
 
96
WindowManager::Undecorate (guint32 xid)
 
97
{
 
98
  MotifWmHints hints = { 0 };
 
99
    
 
100
  hints.flags = MWM_HINTS_DECORATIONS;
 
101
  hints.decorations = 0;
 
102
 
 
103
  gdk_window_set_mwm_hints (xid, &hints);
 
104
}
 
105
 
 
106
/*
 
107
 * Copied over C code
 
108
 */
 
109
static void
 
110
gdk_window_set_mwm_hints (Window        xid,
 
111
                          MotifWmHints *new_hints)
 
112
{
 
113
  GdkDisplay *display = gdk_display_get_default();
 
114
  Atom hints_atom = None;
 
115
  guchar *data = NULL;
 
116
  MotifWmHints *hints = NULL;
 
117
  Atom type = None;
 
118
  gint format;
 
119
  gulong nitems;
 
120
  gulong bytes_after;
 
121
 
 
122
  g_return_if_fail (GDK_IS_DISPLAY (display));
 
123
  
 
124
  hints_atom = gdk_x11_get_xatom_by_name_for_display (display, 
 
125
                                                      _XA_MOTIF_WM_HINTS);
 
126
 
 
127
  gdk_error_trap_push ();
 
128
  XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), 
 
129
                      xid,
 
130
                                  hints_atom, 0, sizeof (MotifWmHints)/sizeof (long),
 
131
                                  False, AnyPropertyType, &type, &format, &nitems,
 
132
                                  &bytes_after, &data);
 
133
  gdk_flush ();
 
134
  if (gdk_error_trap_pop ())
 
135
    {
 
136
      g_debug ("ERROR: Cannot set decorations");
 
137
      return;
 
138
    }
 
139
    
 
140
  if (type != hints_atom || !data)
 
141
    hints = new_hints;
 
142
  else
 
143
  {
 
144
    hints = (MotifWmHints *)data;
 
145
        
 
146
    if (new_hints->flags & MWM_HINTS_FUNCTIONS)
 
147
    {
 
148
      hints->flags |= MWM_HINTS_FUNCTIONS;
 
149
      hints->functions = new_hints->functions;  
 
150
    }
 
151
    if (new_hints->flags & MWM_HINTS_DECORATIONS)
 
152
    {
 
153
      hints->flags |= MWM_HINTS_DECORATIONS;
 
154
      hints->decorations = new_hints->decorations;
 
155
    }
 
156
  }
 
157
  
 
158
  gdk_error_trap_push ();
 
159
  XChangeProperty (GDK_DISPLAY_XDISPLAY (display), 
 
160
                   xid,
 
161
                   hints_atom, hints_atom, 32, PropModeReplace,
 
162
                   (guchar *)hints, sizeof (MotifWmHints)/sizeof (long));
 
163
  gdk_flush ();
 
164
  if (gdk_error_trap_pop ())
 
165
    {
 
166
      g_debug ("ERROR: Setting decorations");
 
167
    }
 
168
  
 
169
  if (data)
 
170
    XFree (data);
 
171
}