aboutsummaryrefslogtreecommitdiffstats
path: root/matchbox2/mb-wm-client-app.c
blob: 3aa9d2ea1ec5bafa7fac57f7c78a541b7d38e23a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#include "mb-wm-client-app.h"

#include "mb-wm-theme.h"

static Bool
mb_wm_client_app_request_geometry (MBWindowManagerClient *client,
				   MBGeometry            *new_geometry,
				   MBWMClientReqGeomType  flags);

static MBWMStackLayerType
mb_wm_client_app_stacking_layer (MBWindowManagerClient *client);

static void
mb_wm_client_app_theme_change (MBWindowManagerClient *client);

static void
mb_wm_client_app_class_init (MBWMObjectClass *klass)
{
  MBWindowManagerClientClass *client;
  MBWMClientAppClass * client_app;

  MBWM_MARK();

  client     = (MBWindowManagerClientClass *)klass;
  client_app = (MBWMClientAppClass *)klass;

  MBWM_DBG("client->stack is %p", client->stack);

  client->client_type = MBWMClientTypeApp;
  client->geometry = mb_wm_client_app_request_geometry;
  client->theme_change = mb_wm_client_app_theme_change;
  client->stacking_layer = mb_wm_client_app_stacking_layer;

#if MBWM_WANT_DEBUG
  klass->klass_name = "MBWMClientApp";
#endif
}

static void
mb_wm_client_app_destroy (MBWMObject *this)
{
}


static int
mb_wm_client_app_init (MBWMObject *this, va_list vap)
{
  MBWindowManagerClient    *client     = MB_WM_CLIENT (this);
  MBWindowManager          *wm = NULL;
  MBWMClientAppClass       *app_class;

  app_class = MB_WM_CLIENT_APP_CLASS (MB_WM_OBJECT_GET_CLASS (this));

#if 0
  /*
   * Property parsing not needed for now, as there are no ClientApp specific
   * properties
   */
  prop = va_arg(vap, MBWMObjectProp);
  while (prop)
    {
      if (prop == MBWMObjectPropWm)
	{
	  wm = va_arg(vap, MBWindowManager *);
	  break;
	}
      else
	MBWMO_PROP_EAT (vap, prop);

      prop = va_arg (vap, MBWMObjectProp);
    }
#endif

  wm = client->wmref;

  if (!wm)
    return 0;

  {
    Atom actions[] = {
      wm->atoms[MBWM_ATOM_NET_WM_ACTION_CLOSE],
      wm->atoms[MBWM_ATOM_NET_WM_ACTION_FULLSCREEN]
    };

    XChangeProperty (wm->xdpy, client->window->xwindow,
		     wm->atoms[MBWM_ATOM_NET_WM_ALLOWED_ACTIONS],
		     XA_ATOM, 32, PropModeReplace,
		     (unsigned char *)actions,
		     sizeof (actions)/sizeof (actions[0]));
  }

  client->stacking_layer = MBWMStackLayerMid;

  mb_wm_client_set_layout_hints (client,
				 LayoutPrefGrowToFreeSpace|LayoutPrefVisible);

  if (!client->window->undecorated)
    {
      mb_wm_theme_create_decor (wm->theme, client, MBWMDecorTypeNorth);
      mb_wm_theme_create_decor (wm->theme, client, MBWMDecorTypeSouth);
      mb_wm_theme_create_decor (wm->theme, client, MBWMDecorTypeWest);
      mb_wm_theme_create_decor (wm->theme, client, MBWMDecorTypeEast);
    }

  return 1;
}

int
mb_wm_client_app_class_type ()
{
  static int type = 0;

  if (UNLIKELY(type == 0))
    {
      static MBWMObjectClassInfo info = {
	sizeof (MBWMClientAppClass),
	sizeof (MBWMClientApp),
	mb_wm_client_app_init,
	mb_wm_client_app_destroy,
	mb_wm_client_app_class_init
      };
      type = mb_wm_object_register_class (&info, MB_WM_TYPE_CLIENT_BASE, 0);
    }

  return type;
}

static Bool
mb_wm_client_app_request_geometry (MBWindowManagerClient *client,
				   MBGeometry            *new_geometry,
				   MBWMClientReqGeomType  flags)
{
  if (flags & (MBWMClientReqGeomIsViaLayoutManager |
	       MBWMClientReqGeomForced             |
	       MBWMClientReqGeomIsViaUserAction))
    {
      int north, south, west, east;
      MBWindowManager *wm = client->wmref;

      if ((client->window->ewmh_state & MBWMClientWindowEWMHStateFullscreen)||
	  !client->decor)
	{
	  /* Undecorated window */
	  client->window->geometry.x      = new_geometry->x;
	  client->window->geometry.y      = new_geometry->y;
	  client->window->geometry.width  = new_geometry->width;
	  client->window->geometry.height = new_geometry->height;

	  client->frame_geometry.x        = new_geometry->x;
	  client->frame_geometry.y        = new_geometry->y;
	  client->frame_geometry.width    = new_geometry->width;
	  client->frame_geometry.height   = new_geometry->height;
	}
      else
	{
	  mb_wm_theme_get_decor_dimensions (wm->theme, client,
					    &north, &south, &west, &east);

	  client->frame_geometry.x      = new_geometry->x;
	  client->frame_geometry.y      = new_geometry->y;
	  client->frame_geometry.width  = new_geometry->width;
	  client->frame_geometry.height = new_geometry->height;

	  client->window->geometry.x
	    = client->frame_geometry.x + west;
	  client->window->geometry.y
	    = client->frame_geometry.y + north;
	  client->window->geometry.width
	    = client->frame_geometry.width - (west + east);
	  client->window->geometry.height
	    = client->frame_geometry.height - (south + north);
	}

      mb_wm_client_geometry_mark_dirty (client);

      return True; /* Geometry accepted */
    }
  
  return False;
}

static void
mb_wm_client_app_theme_change (MBWindowManagerClient *client)
{
  MBWMList * l = client->decor;

  while (l)
    {
      MBWMDecor * d = l->data;
      MBWMList * n = l->next;

      mb_wm_object_unref (MB_WM_OBJECT (d));
      free (l);

      l = n;
    }

  client->decor = NULL;

  if (!client->window->undecorated)
    {
      mb_wm_theme_create_decor (client->wmref->theme,
				client, MBWMDecorTypeNorth);

      mb_wm_theme_create_decor (client->wmref->theme,
				client, MBWMDecorTypeSouth);

      mb_wm_theme_create_decor (client->wmref->theme,
				client, MBWMDecorTypeWest);

      mb_wm_theme_create_decor (client->wmref->theme,
				client, MBWMDecorTypeEast);
    }

  mb_wm_client_geometry_mark_dirty (client);
  mb_wm_client_visibility_mark_dirty (client);
}

static MBWMStackLayerType
mb_wm_client_app_stacking_layer (MBWindowManagerClient *client)
{
  if (client->window->ewmh_state & MBWMClientWindowEWMHStateFullscreen)
    return MBWMStackLayerTopMid;

  return client->stacking_layer;
}

MBWindowManagerClient*
mb_wm_client_app_new (MBWindowManager *wm, MBWMClientWindow *win)
{
  MBWindowManagerClient *client;

  client = MB_WM_CLIENT(mb_wm_object_new (MB_WM_TYPE_CLIENT_APP,
					  MBWMObjectPropWm,           wm,
					  MBWMObjectPropClientWindow, win,
					  NULL));

  return client;
}