forked from awesomeWM/awesome
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.c
More file actions
2034 lines (1801 loc) · 58.5 KB
/
Copy pathclient.c
File metadata and controls
2034 lines (1801 loc) · 58.5 KB
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* client.c - client management
*
* Copyright © 2007-2009 Julien Danjou <julien@danjou.info>
*
* 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 of the License, 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.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <xcb/xcb_atom.h>
#include <xcb/xcb_image.h>
#include "tag.h"
#include "ewmh.h"
#include "screen.h"
#include "titlebar.h"
#include "systray.h"
#include "property.h"
#include "spawn.h"
#include "common/atoms.h"
#include "common/xutil.h"
DO_LUA_TOSTRING(client_t, client, "client")
client_t *
luaA_client_checkudata(lua_State *L, int ud)
{
client_t *c = luaL_checkudata(L, ud, "client");
if(c->invalid)
luaL_error(L, "client is invalid\n");
return c;
}
/** Collect a client.
* \param L The Lua VM state.
* \return The number of element pushed on stack.
*/
static int
luaA_client_gc(lua_State *L)
{
client_t *c = luaL_checkudata(L, 1, "client");
luaA_ref_array_wipe(&c->refs);
button_array_wipe(&c->buttons);
key_array_wipe(&c->keys);
image_unref(L, c->icon);
p_delete(&c->class);
p_delete(&c->startup_id);
p_delete(&c->instance);
p_delete(&c->icon_name);
p_delete(&c->name);
return 0;
}
/** Change the clients urgency flag.
* \param c The client
* \param urgent The new flag state
*/
void
client_seturgent(client_t *c, bool urgent)
{
if(c->isurgent != urgent)
{
xcb_get_property_cookie_t hints =
xcb_get_wm_hints_unchecked(globalconf.connection, c->win);
c->isurgent = urgent;
ewmh_client_update_hints(c);
/* update ICCCM hints */
xcb_wm_hints_t wmh;
xcb_get_wm_hints_reply(globalconf.connection, hints, &wmh, NULL);
if(urgent)
wmh.flags |= XCB_WM_HINT_X_URGENCY;
else
wmh.flags &= ~XCB_WM_HINT_X_URGENCY;
xcb_set_wm_hints(globalconf.connection, c->win, &wmh);
hooks_property(c, "urgent");
}
}
/** Returns true if a client is tagged
* with one of the tags of the specified screen.
* \param c The client to check.
* \param screen Virtual screen.
* \return true if the client is visible, false otherwise.
*/
bool
client_maybevisible(client_t *c, screen_t *screen)
{
if(c->screen == screen)
{
if(c->issticky || c->type == WINDOW_TYPE_DESKTOP)
return true;
foreach(tag, screen->tags)
if((*tag)->selected && is_client_tagged(c, *tag))
return true;
}
return false;
}
/** Return the content of a client as an image.
* That's just take a screenshot.
* \param c The client.
* \return 1 if the image has been pushed on stack, false otherwise.
*/
static int
client_getcontent(client_t *c)
{
xcb_image_t *ximage = xcb_image_get(globalconf.connection,
c->win,
0, 0,
c->geometries.internal.width,
c->geometries.internal.height,
~0, XCB_IMAGE_FORMAT_Z_PIXMAP);
int retval = 0;
if(ximage)
{
if(ximage->bpp >= 24)
{
uint32_t *data = p_alloca(uint32_t, ximage->width * ximage->height);
for(int y = 0; y < ximage->height; y++)
for(int x = 0; x < ximage->width; x++)
{
data[y * ximage->width + x] = xcb_image_get_pixel(ximage, x, y);
data[y * ximage->width + x] |= 0xff000000; /* set alpha to 0xff */
}
retval = image_new_from_argb32(ximage->width, ximage->height, data);
}
xcb_image_destroy(ximage);
}
return retval;
}
/** Get a client by its window.
* \param w The client window to find.
* \return A client pointer if found, NULL otherwise.
*/
client_t *
client_getbywin(xcb_window_t w)
{
foreach(c, globalconf.clients)
if((*c)->win == w)
return *c;
return NULL;
}
/** Record that a client lost focus.
* \param c Client being unfocused
*/
void
client_unfocus_update(client_t *c)
{
globalconf.screens.tab[c->phys_screen].client_focus = NULL;
ewmh_update_net_active_window(c->phys_screen);
/* Call hook */
if(globalconf.hooks.unfocus != LUA_REFNIL)
{
client_push(globalconf.L, c);
luaA_dofunction(globalconf.L, globalconf.hooks.unfocus, 1, 0);
}
}
/** Unfocus a client.
* \param c The client.
*/
void
client_unfocus(client_t *c)
{
xcb_window_t root_win = xutil_screen_get(globalconf.connection, c->phys_screen)->root;
/* Set focus on root window, so no events leak to the current window. */
window_setfocus(root_win, true);
client_unfocus_update(c);
}
/** Ban client and move it out of the viewport.
* \param c The client.
*/
void
client_ban(client_t *c)
{
if(!c->isbanned)
{
/* Move all clients out of the physical viewport into negative coordinate space. */
/* They will all be put on top of each other. */
uint32_t request[2] = { - (c->geometries.internal.width + 2 * c->border),
- (c->geometries.internal.height + 2 * c->border) };
xcb_configure_window(globalconf.connection, c->win,
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
request);
c->isbanned = true;
/* All the wiboxes (may) need to be repositioned. */
if(client_hasstrut(c))
wibox_update_positions();
if(globalconf.screens.tab[c->phys_screen].prev_client_focus == c)
globalconf.screens.tab[c->phys_screen].prev_client_focus = NULL;
/* Wait until the last moment to take away the focus from the window. */
if(globalconf.screens.tab[c->phys_screen].client_focus == c)
client_unfocus(c);
}
}
/** Record that a client got focus.
* \param c Client being focused.
*/
void
client_focus_update(client_t *c)
{
if(!client_maybevisible(c, c->screen))
{
/* Focus previously focused client */
client_focus(globalconf.screen_focus->prev_client_focus);
return;
}
if(globalconf.screen_focus
&& globalconf.screen_focus->client_focus)
{
if (globalconf.screen_focus->client_focus != c)
client_unfocus_update(globalconf.screen_focus->client_focus);
else
/* Already focused */
return;
}
/* stop hiding client */
c->ishidden = false;
client_setminimized(c, false);
/* unban the client before focusing for consistency */
client_unban(c);
globalconf.screen_focus = &globalconf.screens.tab[c->phys_screen];
globalconf.screen_focus->prev_client_focus = c;
globalconf.screen_focus->client_focus = c;
/* Some layouts use focused client differently, so call them back.
* And anyway, we have maybe unhidden */
client_need_arrange(c);
/* according to EWMH, we have to remove the urgent state from a client */
client_seturgent(c, false);
ewmh_update_net_active_window(c->phys_screen);
/* execute hook */
if(globalconf.hooks.focus != LUA_REFNIL)
{
client_push(globalconf.L, c);
luaA_dofunction(globalconf.L, globalconf.hooks.focus, 1, 0);
}
}
/** Give focus to client, or to first client if client is NULL.
* \param c The client or NULL.
*/
void
client_focus(client_t *c)
{
/* We have to set focus on first client */
if(!c && globalconf.clients.len && !(c = globalconf.clients.tab[0]))
return;
if(!client_maybevisible(c, c->screen))
return;
if (!c->nofocus)
client_focus_update(c);
window_setfocus(c->win, !c->nofocus);
}
/** Stack a window below.
* \param c The client.
* \param previous The previous window on the stack.
* \param return The next-previous!
*/
static xcb_window_t
client_stack_above(client_t *c, xcb_window_t previous)
{
uint32_t config_win_vals[2];
config_win_vals[0] = previous;
config_win_vals[1] = XCB_STACK_MODE_ABOVE;
xcb_configure_window(globalconf.connection, c->win,
XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
config_win_vals);
config_win_vals[0] = c->win;
if(c->titlebar)
{
xcb_configure_window(globalconf.connection,
c->titlebar->sw.window,
XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
config_win_vals);
previous = c->titlebar->sw.window;
}
else
previous = c->win;
/* stack transient window on top of their parents */
foreach(node, globalconf.stack)
if((*node)->transient_for == c)
previous = client_stack_above(*node, previous);
return previous;
}
/** Stacking layout layers */
typedef enum
{
/** This one is a special layer */
LAYER_IGNORE,
LAYER_DESKTOP,
LAYER_BELOW,
LAYER_NORMAL,
LAYER_ABOVE,
LAYER_FULLSCREEN,
LAYER_ONTOP,
/** This one only used for counting and is not a real layer */
LAYER_COUNT
} layer_t;
/** Get the real layer of a client according to its attribute (fullscreen, …)
* \param c The client.
* \return The real layer.
*/
static layer_t
client_layer_translator(client_t *c)
{
/* first deal with user set attributes */
if(c->isontop)
return LAYER_ONTOP;
else if(c->isfullscreen)
return LAYER_FULLSCREEN;
else if(c->isabove)
return LAYER_ABOVE;
else if(c->isbelow)
return LAYER_BELOW;
/* check for transient attr */
if(c->transient_for)
return LAYER_IGNORE;
/* then deal with windows type */
switch(c->type)
{
case WINDOW_TYPE_DESKTOP:
return LAYER_DESKTOP;
default:
break;
}
return LAYER_NORMAL;
}
/** Restack clients.
* \todo It might be worth stopping to restack everyone and only stack `c'
* relatively to the first matching in the list.
*/
static void
client_real_stack(void)
{
uint32_t config_win_vals[2];
layer_t layer;
config_win_vals[0] = XCB_NONE;
config_win_vals[1] = XCB_STACK_MODE_ABOVE;
/* stack desktop windows */
for(layer = LAYER_DESKTOP; layer < LAYER_BELOW; layer++)
foreach(node, globalconf.stack)
if(client_layer_translator(*node) == layer)
config_win_vals[0] = client_stack_above(*node,
config_win_vals[0]);
/* first stack not ontop wibox window */
foreach(s, globalconf.screens)
foreach(_sb, s->wiboxes)
{
wibox_t *sb = *_sb;
if(!sb->ontop)
{
xcb_configure_window(globalconf.connection,
sb->sw.window,
XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
config_win_vals);
config_win_vals[0] = sb->sw.window;
}
}
/* then stack clients */
for(layer = LAYER_BELOW; layer < LAYER_COUNT; layer++)
foreach(node, globalconf.stack)
if(client_layer_translator(*node) == layer)
config_win_vals[0] = client_stack_above(*node,
config_win_vals[0]);
/* then stack ontop wibox window */
foreach(s, globalconf.screens)
foreach(_sb, s->wiboxes)
{
wibox_t *sb = *_sb;
if(sb->ontop)
{
xcb_configure_window(globalconf.connection,
sb->sw.window,
XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
config_win_vals);
config_win_vals[0] = sb->sw.window;
}
}
}
void
client_stack_refresh()
{
if (!globalconf.client_need_stack_refresh)
return;
globalconf.client_need_stack_refresh = false;
client_real_stack();
}
/** Manage a new client.
* \param w The window.
* \param wgeom Window geometry.
* \param phys_screen Physical screen number.
* \param startup True if we are managing at startup time.
*/
void
client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen, bool startup)
{
xcb_get_property_cookie_t ewmh_icon_cookie;
screen_t *screen;
const uint32_t select_input_val[] = { CLIENT_SELECT_INPUT_EVENT_MASK };
if(systray_iskdedockapp(w))
{
systray_request_handle(w, phys_screen, NULL);
return;
}
/* Send request to get NET_WM_ICON property as soon as possible... */
ewmh_icon_cookie = ewmh_window_icon_get_unchecked(w);
xcb_change_window_attributes(globalconf.connection, w, XCB_CW_EVENT_MASK, select_input_val);
client_t *c = client_new(globalconf.L);
/* Push client in client list */
client_array_push(&globalconf.clients, client_ref(globalconf.L));
screen = c->screen = screen_getbycoord(&globalconf.screens.tab[phys_screen],
wgeom->x, wgeom->y);
c->phys_screen = phys_screen;
/* Initial values */
c->win = w;
c->geometry.x = wgeom->x;
c->geometry.y = wgeom->y;
/* Border will be added later. */
c->geometry.width = wgeom->width;
c->geometry.height = wgeom->height;
/* Also set internal geometry (client_ban() needs it). */
c->geometries.internal.x = wgeom->x;
c->geometries.internal.y = wgeom->y;
c->geometries.internal.width = wgeom->width;
c->geometries.internal.height = wgeom->height;
client_setborder(c, wgeom->border_width);
if(ewmh_window_icon_get_reply(ewmh_icon_cookie))
c->icon = image_ref(globalconf.L);
/* we honor size hints by default */
c->size_hints_honor = true;
/* update hints */
property_update_wm_normal_hints(c, NULL);
property_update_wm_hints(c, NULL);
property_update_wm_transient_for(c, NULL);
property_update_wm_client_leader(c, NULL);
/* Then check clients hints */
ewmh_client_check_hints(c);
/* move client to screen, but do not tag it */
screen_client_moveto(c, screen, false, true);
/* Push client in stack */
client_raise(c);
/* update window title */
property_update_wm_name(c);
property_update_wm_icon_name(c);
property_update_wm_class(c, NULL);
xutil_text_prop_get(globalconf.connection, c->win, _NET_STARTUP_ID, &c->startup_id, NULL);
/* update strut */
ewmh_process_client_strut(c, NULL);
ewmh_update_net_client_list(c->phys_screen);
/* Always stay in NORMAL_STATE. Even though iconified seems more
* appropriate sometimes. The only possible loss is that clients not using
* visibility events may continue to proces data (when banned).
* Without any exposes or other events the cost should be fairly limited though.
*
* Some clients may expect the window to be unmapped when STATE_ICONIFIED.
* Two conflicting parts of the ICCCM v2.0 (section 4.1.4):
*
* "Normal -> Iconic - The client should send a ClientMessage event as described later in this section."
* (note no explicit mention of unmapping, while Normal->Widthdrawn does mention that)
*
* "Once a client's window has left the Withdrawn state, the window will be mapped
* if it is in the Normal state and the window will be unmapped if it is in the Iconic state."
*
* At this stage it's just safer to keep it in normal state and avoid confusion.
*/
window_state_set(c->win, XCB_WM_STATE_NORMAL);
/* Move window outside the viewport before mapping it. */
client_ban(c);
xcb_map_window(globalconf.connection, c->win);
if(!startup)
spawn_start_notify(c);
/* Call hook to notify list change */
if(globalconf.hooks.clients != LUA_REFNIL)
luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
/* call hook */
if(globalconf.hooks.manage != LUA_REFNIL)
{
client_push(globalconf.L, c);
lua_pushboolean(globalconf.L, startup);
luaA_dofunction(globalconf.L, globalconf.hooks.manage, 2, 0);
}
}
/** Compute client geometry with respect to its geometry hints.
* \param c The client.
* \param geometry The geometry that the client might receive.
* \return The geometry the client must take respecting its hints.
*/
area_t
client_geometry_hints(client_t *c, area_t geometry)
{
int32_t basew, baseh, minw, minh;
/* base size is substituted with min size if not specified */
if(c->size_hints.flags & XCB_SIZE_HINT_P_SIZE)
{
basew = c->size_hints.base_width;
baseh = c->size_hints.base_height;
}
else if(c->size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE)
{
basew = c->size_hints.min_width;
baseh = c->size_hints.min_height;
}
else
basew = baseh = 0;
/* min size is substituted with base size if not specified */
if(c->size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE)
{
minw = c->size_hints.min_width;
minh = c->size_hints.min_height;
}
else if(c->size_hints.flags & XCB_SIZE_HINT_P_SIZE)
{
minw = c->size_hints.base_width;
minh = c->size_hints.base_height;
}
else
minw = minh = 0;
if(c->size_hints.flags & XCB_SIZE_HINT_P_ASPECT
&& c->size_hints.min_aspect_num > 0
&& c->size_hints.min_aspect_den > 0
&& geometry.height - baseh > 0
&& geometry.width - basew > 0)
{
double dx = (double) (geometry.width - basew);
double dy = (double) (geometry.height - baseh);
double min = (double) c->size_hints.min_aspect_num / (double) c->size_hints.min_aspect_den;
double max = (double) c->size_hints.max_aspect_num / (double) c->size_hints.min_aspect_den;
double ratio = dx / dy;
if(max > 0 && min > 0 && ratio > 0)
{
if(ratio < min)
{
dy = (dx * min + dy) / (min * min + 1);
dx = dy * min;
geometry.width = (int) dx + basew;
geometry.height = (int) dy + baseh;
}
else if(ratio > max)
{
dy = (dx * min + dy) / (max * max + 1);
dx = dy * min;
geometry.width = (int) dx + basew;
geometry.height = (int) dy + baseh;
}
}
}
if(minw)
geometry.width = MAX(geometry.width, minw);
if(minh)
geometry.height = MAX(geometry.height, minh);
if(c->size_hints.flags & XCB_SIZE_HINT_P_MAX_SIZE)
{
if(c->size_hints.max_width)
geometry.width = MIN(geometry.width, c->size_hints.max_width);
if(c->size_hints.max_height)
geometry.height = MIN(geometry.height, c->size_hints.max_height);
}
if(c->size_hints.flags & (XCB_SIZE_HINT_P_RESIZE_INC | XCB_SIZE_HINT_BASE_SIZE)
&& c->size_hints.width_inc && c->size_hints.height_inc)
{
uint16_t t1 = geometry.width, t2 = geometry.height;
unsigned_subtract(t1, basew);
unsigned_subtract(t2, baseh);
geometry.width -= t1 % c->size_hints.width_inc;
geometry.height -= t2 % c->size_hints.height_inc;
}
return geometry;
}
/** Resize client window.
* The sizse given as parameters are with titlebar and borders!
* \param c Client to resize.
* \param geometry New window geometry.
* \param hints Use size hints.
* \return true if an actual resize occurred.
*/
bool
client_resize(client_t *c, area_t geometry, bool hints)
{
area_t geometry_internal;
area_t area;
/* offscreen appearance fixes */
area = display_area_get(c->phys_screen, NULL,
&c->screen->padding);
if(geometry.x > area.width)
geometry.x = area.width - geometry.width;
if(geometry.y > area.height)
geometry.y = area.height - geometry.height;
if(geometry.x + geometry.width < 0)
geometry.x = 0;
if(geometry.y + geometry.height < 0)
geometry.y = 0;
/* Real client geometry, please keep it contained to C code at the very least. */
geometry_internal = titlebar_geometry_remove(c->titlebar, c->border, geometry);
if(hints)
geometry_internal = client_geometry_hints(c, geometry_internal);
if(geometry_internal.width == 0 || geometry_internal.height == 0)
return false;
/* Also let client hints propegate to the "official" geometry. */
geometry = titlebar_geometry_add(c->titlebar, c->border, geometry_internal);
if(c->geometries.internal.x != geometry_internal.x
|| c->geometries.internal.y != geometry_internal.y
|| c->geometries.internal.width != geometry_internal.width
|| c->geometries.internal.height != geometry_internal.height)
{
screen_t *new_screen = screen_getbycoord(c->screen,
geometry_internal.x, geometry_internal.y);
/* Values to configure a window is an array where values are
* stored according to 'value_mask' */
uint32_t values[4];
c->geometries.internal.x = values[0] = geometry_internal.x;
c->geometries.internal.y = values[1] = geometry_internal.y;
c->geometries.internal.width = values[2] = geometry_internal.width;
c->geometries.internal.height = values[3] = geometry_internal.height;
/* Also store geometry including border and titlebar. */
c->geometry = geometry;
titlebar_update_geometry(c);
/* The idea is to give a client a resize even when banned. */
/* We just have to move the (x,y) to keep it out of the viewport. */
/* This at least doesn't break expectations about events. */
if(c->isbanned)
{
geometry_internal.x = values[0] = - (geometry_internal.width + 2 * c->border);
geometry_internal.y = values[1] = - (geometry_internal.height + 2 * c->border);
}
xcb_configure_window(globalconf.connection, c->win,
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y
| XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
values);
screen_client_moveto(c, new_screen, true, false);
/* execute hook */
hooks_property(c, "geometry");
return true;
}
return false;
}
/** Set a client minimized, or not.
* \param c The client.
* \param s Set or not the client minimized.
*/
void
client_setminimized(client_t *c, bool s)
{
if(c->isminimized != s)
{
client_need_arrange(c);
c->isminimized = s;
client_need_arrange(c);
ewmh_client_update_hints(c);
/* execute hook */
hooks_property(c, "minimized");
}
}
/** Set a client sticky, or not.
* \param c The client.
* \param s Set or not the client sticky.
*/
void
client_setsticky(client_t *c, bool s)
{
if(c->issticky != s)
{
client_need_arrange(c);
c->issticky = s;
client_need_arrange(c);
ewmh_client_update_hints(c);
hooks_property(c, "sticky");
}
}
/** Set a client fullscreen, or not.
* \param c The client.
* \param s Set or not the client fullscreen.
*/
void
client_setfullscreen(client_t *c, bool s)
{
if(c->isfullscreen != s)
{
area_t geometry;
/* Make sure the current geometry is stored without titlebar. */
if(s)
titlebar_ban(c->titlebar);
/* become fullscreen! */
if((c->isfullscreen = s))
{
/* remove any max state */
client_setmaxhoriz(c, false);
client_setmaxvert(c, false);
/* You can only be part of one of the special layers. */
client_setbelow(c, false);
client_setabove(c, false);
client_setontop(c, false);
geometry = screen_area_get(c->screen, NULL, NULL, false);
c->geometries.fullscreen = c->geometry;
c->border_fs = c->border;
client_setborder(c, 0);
}
else
{
geometry = c->geometries.fullscreen;
client_setborder(c, c->border_fs);
}
client_resize(c, geometry, false);
client_need_arrange(c);
client_stack();
ewmh_client_update_hints(c);
hooks_property(c, "fullscreen");
}
}
/** Set a client horizontally maximized.
* \param c The client.
* \param s The maximized status.
*/
void
client_setmaxhoriz(client_t *c, bool s)
{
if(c->ismaxhoriz != s)
{
area_t geometry;
if((c->ismaxhoriz = s))
{
/* remove fullscreen mode */
client_setfullscreen(c, false);
geometry = screen_area_get(c->screen,
&c->screen->wiboxes,
&c->screen->padding,
true);
geometry.y = c->geometry.y;
geometry.height = c->geometry.height;
c->geometries.max.x = c->geometry.x;
c->geometries.max.width = c->geometry.width;
}
else
{
geometry = c->geometry;
geometry.x = c->geometries.max.x;
geometry.width = c->geometries.max.width;
}
client_resize(c, geometry, c->size_hints_honor);
client_need_arrange(c);
client_stack();
ewmh_client_update_hints(c);
hooks_property(c, "maximized_horizontal");
}
}
/** Set a client vertically maximized.
* \param c The client.
* \param s The maximized status.
*/
void
client_setmaxvert(client_t *c, bool s)
{
if(c->ismaxvert != s)
{
area_t geometry;
if((c->ismaxvert = s))
{
/* remove fullscreen mode */
client_setfullscreen(c, false);
geometry = screen_area_get(c->screen,
&c->screen->wiboxes,
&c->screen->padding,
true);
geometry.x = c->geometry.x;
geometry.width = c->geometry.width;
c->geometries.max.y = c->geometry.y;
c->geometries.max.height = c->geometry.height;
}
else
{
geometry = c->geometry;
geometry.y = c->geometries.max.y;
geometry.height = c->geometries.max.height;
}
client_resize(c, geometry, c->size_hints_honor);
client_need_arrange(c);
client_stack();
ewmh_client_update_hints(c);
hooks_property(c, "maximized_vertical");
}
}
/** Set a client above, or not.
* \param c The client.
* \param s Set or not the client above.
*/
void
client_setabove(client_t *c, bool s)
{
if(c->isabove != s)
{
/* You can only be part of one of the special layers. */
if(s)
{
client_setbelow(c, false);
client_setontop(c, false);
client_setfullscreen(c, false);
}
c->isabove = s;
client_stack();
ewmh_client_update_hints(c);
/* execute hook */
hooks_property(c, "above");
}
}
/** Set a client below, or not.
* \param c The client.
* \param s Set or not the client below.
*/
void
client_setbelow(client_t *c, bool s)
{
if(c->isbelow != s)
{
/* You can only be part of one of the special layers. */
if(s)
{
client_setabove(c, false);
client_setontop(c, false);
client_setfullscreen(c, false);
}
c->isbelow = s;
client_stack();
ewmh_client_update_hints(c);
/* execute hook */
hooks_property(c, "below");
}
}
/** Set a client modal, or not.
* \param c The client.
* \param s Set or not the client moda.
*/
void
client_setmodal(client_t *c, bool s)
{
if(c->ismodal != s)
{
c->ismodal = s;
client_stack();
ewmh_client_update_hints(c);
/* execute hook */
hooks_property(c, "modal");
}
}
/** Set a client ontop, or not.
* \param c The client.
* \param s Set or not the client moda.
*/
void
client_setontop(client_t *c, bool s)
{
if(c->isontop != s)
{
/* You can only be part of one of the special layers. */
if(s)
{
client_setabove(c, false);
client_setbelow(c, false);
client_setfullscreen(c, false);
}
c->isontop = s;
client_stack();
/* execute hook */
hooks_property(c, "ontop");
}
}
/** Unban a client and move it back into the viewport.
* \param c The client.