aboutsummaryrefslogtreecommitdiffstats
path: root/src/dockbar_client.c
blob: 836c003f3aceea27f363ef7ee00781cf16e4b2b7 (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
/* 
 *  Matchbox Window Manager - A lightweight window manager not for the
 *                            desktop.
 *
 *  Authored By Matthew Allum <mallum@o-hand.com>
 *
 *  Copyright (c) 2002, 2004 OpenedHand Ltd - http://o-hand.com
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 */

/* 
 *  a Dockbar is a *Panel*.
 */

#include "dockbar_client.h"

static int dockbar_client_orientation_calc(Client *c);

Client*
dockbar_client_new(Wm *w, Window win)
{
   Client *c = base_client_new(w, win); 

   if (!c) return NULL;

   c->type         = MBCLIENT_TYPE_PANEL;
   c->configure    = &dockbar_client_configure;
   c->show         = &dockbar_client_show;
   c->hide         = &dockbar_client_hide;
   c->move_resize  = &dockbar_client_move_resize;
   c->destroy      = &dockbar_client_destroy;

   c->flags        = dockbar_client_orientation_calc(c);
   
   c->frame = c->window;

   return c;
}

static int
dockbar_client_orientation_calc(Client *c)
{
  Wm *w = c->wm;

  dbg("%s() called, x:%i, y:%i, w:%i h:%i\n", __func__, 
      c->x, c->y, c->width, c->height);

  /*   - Can only have one titlebar panel  
   *   - if theme does not have title bar it wont get mapped. 
   */
  if (!w->have_titlebar_panel) /* && mbtheme_has_titlebar_panel(w->mbtheme)) */
    {
      if (ewmh_state_check(c, c->wm->atoms[MB_WM_STATE_DOCK_TITLEBAR]))
	{
	  w->have_titlebar_panel = c;

	  /* Does the panel still want to be shown when we map the desktop ? */
	  if (ewmh_state_check(c, c->wm->atoms[MB_DOCK_TITLEBAR_SHOW_ON_DESKTOP]))
	    return CLIENT_DOCK_TITLEBAR|CLIENT_DOCK_TITLEBAR_SHOW_ON_DESKTOP;

	  return CLIENT_DOCK_TITLEBAR;
	}
    }

  if (c->width > c->height)	/* Assume Horizonal north/south Dock */
    {
      if (c->y < (w->dpy_height/2))
	return CLIENT_DOCK_NORTH;
      else
	return CLIENT_DOCK_SOUTH;
    }
  else
    {
      if (c->x < (w->dpy_width/2))
	return CLIENT_DOCK_WEST;
      else
	return CLIENT_DOCK_EAST;
    }
}

void
dockbar_client_configure(Client *c)
{
  Wm *w = c->wm;

  int n_offset = wm_get_offsets_size(c->wm, NORTH, c, False);
  int s_offset = wm_get_offsets_size(c->wm, SOUTH, c, False);
  int e_offset = wm_get_offsets_size(c->wm, EAST,  c, True);
  int w_offset = wm_get_offsets_size(c->wm, WEST,  c, True);
   
  /* XXX - we should check for overlapping and if this happens
     change em to normal clients. 
  */

   if (c->flags & CLIENT_DOCK_NORTH)
     {
       c->y = n_offset;
       c->x = w_offset;
       c->width  = w->dpy_width - e_offset - w_offset;
     }
   else if (c->flags & CLIENT_DOCK_SOUTH)
     {
       c->y = w->dpy_height - s_offset - c->height;
       c->x = w_offset;
       c->width  = w->dpy_width - e_offset - w_offset;
     }
   else if (c->flags & CLIENT_DOCK_WEST)
     {
       c->y = 0;
       c->x = w_offset;
       c->height = w->dpy_height;
     }
   else if (c->flags & CLIENT_DOCK_EAST)
     {
       c->y = 0;
       c->x = w->dpy_width - e_offset - c->width;
       c->height = w->dpy_height;
     }
   else if (c->flags & CLIENT_DOCK_TITLEBAR)
     {
       XRectangle rect;

       mbtheme_get_titlebar_panel_rect(w->mbtheme, &rect, NULL);
 
       c->x      = rect.x + w_offset; 
       c->y      = rect.y + n_offset;
       c->width  = rect.width;
       c->height = rect.height;
     }
   else
     {
       dbg("%s() : EEEK no dock type flag set !\n", __func__ );
     }

   dbg("%s() sizing as %i %i %i %i", __func__, c->x, c->y, 
       c->width, c->height);
   
   XSetWindowBorderWidth(w->dpy, c->window, 0);
   XSetWindowBorder(w->dpy, c->window, 0);
   
}

void
dockbar_client_move_resize(Client *c)
{
  Wm *w = c->wm;

  base_client_move_resize(c);

  dbg("%s() to %s  x: %i , y: %i w: %i h: %i \n", 
      __func__, c->name, c->x, c->y, c->width, c->height);

  XResizeWindow(w->dpy, c->window, c->width, c->height);
  XMoveWindow(w->dpy, c->window, c->x, c->y);
}

void
dockbar_client_show(Client *c) /*TODO: show and hide share common static func*/
{
  Wm *w = c->wm;

  if (client_get_state(c) == NormalState) return;

  dbg("%s() called\n", __func__);
  
  XGrabServer(w->dpy);
  
  c->mapped = True;
  
  if (c->flags & CLIENT_DOCK_EAST || c->flags & CLIENT_DOCK_WEST)
    wm_update_layout(c->wm, c, - c->width);
  else if ( c->flags & CLIENT_DOCK_NORTH )
    {
      wm_update_layout(c->wm, c, - c->height);
    }
  else if ( c->flags & CLIENT_DOCK_SOUTH )
    wm_update_layout(c->wm, c, - c->height);
  
  client_set_state(c, NormalState);

  XMapWindow(w->dpy, c->window);

  stack_move_client_above_type(c, MBCLIENT_TYPE_APP|MBCLIENT_TYPE_DESKTOP);

  XUngrabServer(w->dpy);
}

void
dockbar_client_hide(Client *c)
{
  Wm *w = c->wm;

  if (client_get_state(c) == IconicState) return;
  XGrabServer(w->dpy);
  client_set_state(c, IconicState);
  
  c->mapped = False; 		/* Same reasoning as toolbar_destroy */
  
  if (c->flags & CLIENT_DOCK_EAST || c->flags & CLIENT_DOCK_WEST)
    wm_update_layout(c->wm, c, c->width);
  else if (!(c->flags & CLIENT_DOCK_TITLEBAR))
    wm_update_layout(c->wm, c, c->height);
  
  base_client_hide(c);
  
  XUngrabServer(w->dpy);
}

void
dockbar_client_destroy(Client *c)
{
  Wm *w = c->wm;
  if (c == w->have_titlebar_panel)
    w->have_titlebar_panel = NULL;
  
  c->mapped = False;
  
  if (c->flags & CLIENT_DOCK_EAST || c->flags & CLIENT_DOCK_WEST)
    wm_update_layout(c->wm, c, c->width );
  else if (!(c->flags & CLIENT_DOCK_TITLEBAR))
    wm_update_layout(c->wm, c, c->height);
  
  base_client_destroy(c);
}