-
-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathfocus.c
More file actions
1258 lines (1119 loc) · 26.2 KB
/
focus.c
File metadata and controls
1258 lines (1119 loc) · 26.2 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
/* -*-c-*- */
/* 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, see: <http://www.gnu.org/licenses/>
*/
/* ---------------------------- included header files ---------------------- */
#include "config.h"
#include <stdio.h>
#include "libs/fvwmlib.h"
#include "libs/charmap.h"
#include "libs/wcontext.h"
#include "libs/ClientMsg.h"
#include "libs/Grab.h"
#include "libs/Parse.h"
#include "libs/Strings.h"
#include "libs/FEvent.h"
#include "fvwm.h"
#include "externs.h"
#include "execcontext.h"
#include "eventhandler.h"
#include "bindings.h"
#include "misc.h"
#include "screen.h"
#include "focus.h"
#include "borders.h"
#include "frame.h"
#include "virtual.h"
#include "stack.h"
#include "geometry.h"
#include "colormaps.h"
#include "add_window.h"
/* ---------------------------- local definitions -------------------------- */
/* ---------------------------- local macros ------------------------------- */
/* ---------------------------- imports ------------------------------------ */
/* ---------------------------- included code files ------------------------ */
/* ---------------------------- local types -------------------------------- */
typedef struct
{
unsigned do_allow_force_broadcast : 1;
unsigned do_forbid_warp : 1;
unsigned do_force : 1;
unsigned is_focus_by_flip_focus_cmd : 1;
unsigned client_entered : 1;
fpol_set_focus_by_t set_by;
} sftfwin_args_t;
/* ---------------------------- forward declarations ----------------------- */
/* ---------------------------- local variables ---------------------------- */
static Bool lastFocusType;
/* Last window which Fvwm gave the focus to NOT the window that really has the
* focus */
static FvwmWindow *ScreenFocus = NULL;
/* ---------------------------- exported variables (globals) --------------- */
/* ---------------------------- interface functions ------------------------ */
void _focus_set(Window w, FvwmWindow *fw)
{
Scr.focus_in_requested_window = fw;
XSetInputFocus(dpy, w, RevertToParent, fev_get_evtime());
return;
}
void _focus_reset(void)
{
Scr.focus_in_requested_window = NULL;
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, fev_get_evtime());
return;
}
/* ---------------------------- local functions ---------------------------- */
static Bool focus_get_fpol_context_flag(
fpol_context_t *fpol_context, int context)
{
int flag;
switch (context)
{
case C_WINDOW:
case C_EWMH_DESKTOP:
flag = fpol_context->client;
break;
case C_ICON:
flag = fpol_context->icon;
break;
default:
flag = fpol_context->decor;
break;
}
return (flag) ? True : False;
}
/*
* Helper functions for setting the focus
*/
static void _try_program_focus(Window w, const FvwmWindow *fw)
{
if (fw && WM_TAKES_FOCUS(fw) &&
FP_DO_FOCUS_BY_PROGRAM(FW_FOCUS_POLICY(fw)))
{
send_clientmessage(dpy, w, _XA_WM_TAKE_FOCUS, fev_get_evtime());
}
return;
}
static Bool _try_forbid_user_focus(
Window w, FvwmWindow *fw)
{
if (fw == NULL ||
fpol_query_allow_user_focus(&FW_FOCUS_POLICY(fw)) == True)
{
return False;
}
if (WM_TAKES_FOCUS(fw))
{
/* give it a chance to take the focus itself */
_try_program_focus(w, fw);
XFlush(dpy);
}
else
{
/* make sure the window is not hilighted */
border_draw_decorations(
fw, PART_ALL, False, False, CLEAR_ALL, NULL, NULL);
}
return True;
}
static Bool _check_allow_focus(
Window w, FvwmWindow *fw, fpol_set_focus_by_t set_by)
{
FvwmWindow *sf;
struct monitor *m;
if (fw == NULL || set_by == FOCUS_SET_FORCE)
{
/* always allow to delete focus */
return True;
}
m = fw->m;
sf = get_focus_window();
if (!FP_IS_LENIENT(FW_FOCUS_POLICY(fw)) &&
!focus_does_accept_input_focus(fw) &&
sf != NULL && sf->Desk == m->virtual_scr.CurrentDesk)
{
/* window does not want focus */
return False;
}
if (fpol_query_allow_set_focus(&FW_FOCUS_POLICY(fw), set_by))
{
return True;
}
return False;
}
static void _update_windowlist(
FvwmWindow *fw, fpol_set_focus_by_t set_by,
int is_focus_by_flip_focus_cmd)
{
lastFocusType = (is_focus_by_flip_focus_cmd) ? True : False;
if (fw == NULL || focus_is_focused(fw) || fw == &Scr.FvwmRoot ||
IS_SCHEDULED_FOR_DESTROY(fw))
{
return;
}
/* Watch out: fw may not be on the windowlist and the windowlist may be
* empty */
if (!is_focus_by_flip_focus_cmd &&
(FP_DO_SORT_WINDOWLIST_BY(FW_FOCUS_POLICY(fw)) ==
FPOL_SORT_WL_BY_OPEN ||
set_by == FOCUS_SET_BY_FUNCTION))
{
/* move the windowlist around so that fw is at the top */
FvwmWindow *fw2;
/* find the window on the windowlist */
for (fw2 = &Scr.FvwmRoot; fw2 && fw2 != fw; fw2 = fw2->next)
{
/* nothing */
}
if (fw2)
{
/* the window is on the (non-zero length) windowlist */
/* make fw2 point to the last window on the list */
while (fw2->next)
{
fw2 = fw2->next;
}
/* close the ends of the windowlist */
fw2->next = Scr.FvwmRoot.next;
Scr.FvwmRoot.next->prev = fw2;
/* make fw the new start of the list */
Scr.FvwmRoot.next = fw;
/* open the closed loop windowlist */
fw->prev->next = NULL;
fw->prev = &Scr.FvwmRoot;
}
}
else
{
/* pluck window from list and deposit at top */
/* remove fw from list */
if (fw->prev)
{
fw->prev->next = fw->next;
}
if (fw->next)
{
fw->next->prev = fw->prev;
}
/* insert fw at start */
fw->next = Scr.FvwmRoot.next;
if (Scr.FvwmRoot.next)
{
Scr.FvwmRoot.next->prev = fw;
}
Scr.FvwmRoot.next = fw;
fw->prev = &Scr.FvwmRoot;
}
return;
}
/*
* Sets the input focus to the indicated window.
*/
static void _set_focus_to_fwin(
Window w, FvwmWindow *fw, sftfwin_args_t *args)
{
FvwmWindow *sf;
struct monitor *m;
if (_try_forbid_user_focus(w, fw) == True)
{
return;
}
_try_program_focus(w, fw);
if (_check_allow_focus(w, fw, args->set_by) == False)
{
return;
}
_update_windowlist(fw, args->set_by, args->is_focus_by_flip_focus_cmd);
if (fw && !args->do_forbid_warp)
{
if (IS_ICONIFIED(fw))
{
rectangle r;
Bool rc;
rc = get_visible_icon_geometry(fw, &r);
if (!rc || !IsRectangleOnThisPage(fw->m, &r, fw->Desk))
{
fw = NULL;
w = Scr.NoFocusWin;
}
}
else if (!IsRectangleOnThisPage(fw->m, &(fw->g.frame), fw->Desk))
{
fw = NULL;
w = Scr.NoFocusWin;
}
}
sf = get_focus_window();
if (fw == NULL)
{
FOCUS_SET(Scr.NoFocusWin, NULL);
set_focus_window(NULL);
Scr.UnknownWinFocused = None;
XFlush(dpy);
return;
}
m = fw->m;
/* RBW - allow focus to go to a NoIconTitle icon window so
* auto-raise will work on it. */
if (IS_ICONIFIED(fw))
{
Bool is_window_selected = False;
if (FW_W_ICON_TITLE(fw))
{
w = FW_W_ICON_TITLE(fw);
is_window_selected = True;
}
if ((!is_window_selected || WAS_ICON_HINT_PROVIDED(fw)) &&
FW_W_ICON_PIXMAP(fw))
{
w = FW_W_ICON_PIXMAP(fw);
}
}
if (FP_IS_LENIENT(FW_FOCUS_POLICY(fw)))
{
FOCUS_SET(w, fw);
set_focus_window(fw);
if (args->do_allow_force_broadcast)
{
SET_FOCUS_CHANGE_BROADCAST_PENDING(fw, 1);
}
Scr.UnknownWinFocused = None;
}
else if (focus_does_accept_input_focus(fw))
{
/* Window will accept input focus */
if (Scr.StolenFocusWin == w && Scr.UnknownWinFocused != None)
{
/* Without this FocusIn is not generated on the
* window if it was focuesed when the unmanaged
* window took focus. */
FOCUS_SET(Scr.NoFocusWin, NULL);
}
FOCUS_SET(w, fw);
set_focus_window(fw);
if (fw)
{
if (args->do_allow_force_broadcast)
{
SET_FOCUS_CHANGE_BROADCAST_PENDING(fw, 1);
}
}
Scr.UnknownWinFocused = None;
}
else if (sf && sf->Desk == m->virtual_scr.CurrentDesk)
{
/* Window doesn't want focus. Leave focus alone */
}
else
{
FOCUS_SET(Scr.NoFocusWin, NULL);
set_focus_window(NULL);
}
XFlush(dpy);
return;
}
static void set_focus_to_fwin(
Window w, FvwmWindow *fw, sftfwin_args_t *args)
{
FvwmWindow *sf;
sf = get_focus_window();
if (!args->do_force && fw == sf)
{
focus_grab_buttons(sf);
return;
}
_set_focus_to_fwin(w, fw, args);
/* Make sure the button grabs on the new and the old focused windows
* are up to date. */
if (args->client_entered)
{
focus_grab_buttons_client_entered(fw);
}
else
{
focus_grab_buttons(fw);
}
/* RBW -- don't call this twice for the same window! */
if (fw != get_focus_window())
{
if (args->client_entered)
{
focus_grab_buttons_client_entered(get_focus_window());
}
else
{
focus_grab_buttons(get_focus_window());
}
}
return;
}
/*
*
* Moves pointer to specified window
*
*/
static void warp_to_fvwm_window(
const exec_context_t *exc, int warp_x, int x_unit, int warp_y,
int y_unit, int do_raise)
{
int dx,dy;
int cx,cy;
int x,y;
FvwmWindow *t = exc->w.fw;
struct monitor *m;
if (t == (FvwmWindow *)0 ||
(IS_ICONIFIED(t) && FW_W_ICON_TITLE(t) == None))
{
return;
}
m = t->m;
if (t->Desk != m->virtual_scr.CurrentDesk)
{
goto_desk(t->Desk, m);
}
if (IS_ICONIFIED(t))
{
rectangle g;
Bool rc;
rc = get_visible_icon_title_geometry(t, &g);
if (rc == False)
{
get_visible_icon_picture_geometry(t, &g);
}
cx = g.x + g.width / 2;
cy = g.y + g.height / 2;
}
else
{
cx = t->g.frame.x + t->g.frame.width/2;
cy = t->g.frame.y + t->g.frame.height/2;
}
dx = (cx + m->virtual_scr.Vx) / monitor_get_all_widths() * monitor_get_all_widths();
dy = (cy + m->virtual_scr.Vy) / monitor_get_all_heights() * monitor_get_all_heights();
if (dx != m->virtual_scr.Vx || dy != m->virtual_scr.Vy)
{
MoveViewport(m, dx, dy, True);
}
if (IS_ICONIFIED(t))
{
rectangle g;
Bool rc;
rc = get_visible_icon_title_geometry(t, &g);
if (rc == False)
{
get_visible_icon_picture_geometry(t, &g);
}
x = g.x + g.width / 2;
y = g.y + g.height / 2;
}
else
{
if (x_unit != monitor_get_all_widths() && warp_x >= 0)
{
x = t->g.frame.x + warp_x;
}
else if (x_unit != monitor_get_all_widths())
{
x = t->g.frame.x + t->g.frame.width + warp_x;
}
else if (warp_x >= 0)
{
x = t->g.frame.x +
(t->g.frame.width - 1) * warp_x / 100;
}
else
{
x = t->g.frame.x +
(t->g.frame.width - 1) * (100 + warp_x) / 100;
}
if (y_unit != monitor_get_all_heights() && warp_y >= 0)
{
y = t->g.frame.y + warp_y;
}
else if (y_unit != monitor_get_all_heights())
{
y = t->g.frame.y + t->g.frame.height + warp_y;
}
else if (warp_y >= 0)
{
y = t->g.frame.y +
(t->g.frame.height - 1) * warp_y / 100;
}
else
{
y = t->g.frame.y +
(t->g.frame.height - 1) * (100 + warp_y) / 100;
}
}
FWarpPointerUpdateEvpos(
exc->x.elast, dpy, None, Scr.Root, 0, 0, 0, 0, x, y);
if (do_raise)
{
RaiseWindow(t, False);
}
/* If the window is still not visible, make it visible! */
if (t->g.frame.x + t->g.frame.width < 0 ||
t->g.frame.y + t->g.frame.height < 0 ||
t->g.frame.x >= monitor_get_all_widths() ||
t->g.frame.y >= monitor_get_all_heights())
{
frame_setup_window(
t, 0, 0, t->g.frame.width, t->g.frame.height, False);
FWarpPointerUpdateEvpos(
exc->x.elast, dpy, None, Scr.Root, 0, 0, 0, 0, 2, 2);
}
return;
}
static Bool focus_query_grab_buttons(FvwmWindow *fw, Bool client_entered)
{
Bool flag;
Bool is_focused;
struct monitor *m = fw->m;
if (fw->Desk != m->virtual_scr.CurrentDesk || IS_ICONIFIED(fw))
{
return False;
}
is_focused = focus_is_focused(fw);
if (!is_focused && FP_DO_FOCUS_CLICK_CLIENT(FW_FOCUS_POLICY(fw)))
{
return True;
}
if (is_on_top_of_layer_and_above_unmanaged(fw))
{
return False;
}
if (is_focused)
{
flag = FP_DO_RAISE_FOCUSED_CLIENT_CLICK(FW_FOCUS_POLICY(fw));
}
else
{
flag = FP_DO_RAISE_UNFOCUSED_CLIENT_CLICK(FW_FOCUS_POLICY(fw));
}
return (flag) ? True : False;
}
static FvwmWindow *_restore_focus_after_unmap(
const FvwmWindow *fw, Bool do_skip_marked_transients)
{
FvwmWindow *t = NULL;
FvwmWindow *set_focus_to = NULL;
t = get_transientfor_fvwmwindow(fw);
if (t != NULL &&
FP_DO_RELEASE_FOCUS_TRANSIENT(FW_FOCUS_POLICY(fw)) &&
!FP_DO_OVERRIDE_RELEASE_FOCUS(FW_FOCUS_POLICY(t)) &&
t->Desk == fw->Desk &&
(!do_skip_marked_transients || !IS_IN_TRANSIENT_SUBTREE(t)))
{
set_focus_to = t;
}
else if (t == NULL && FP_DO_RELEASE_FOCUS(FW_FOCUS_POLICY(fw)))
{
for (t = fw->next; t != NULL && set_focus_to == NULL;
t = t->next)
{
if (!FP_DO_OVERRIDE_RELEASE_FOCUS(
FW_FOCUS_POLICY(t)) &&
t->Desk == fw->Desk && !DO_SKIP_CIRCULATE(t) &&
!(IS_ICONIFIED(t) && (DO_SKIP_ICON_CIRCULATE(t) ||
IS_ICON_SUPPRESSED(t))) &&
(!do_skip_marked_transients ||
!IS_IN_TRANSIENT_SUBTREE(t)))
{
/* If it is on a different desk we have to look
* for another window */
set_focus_to = t;
}
}
}
if (set_focus_to && set_focus_to != fw &&
set_focus_to->Desk == fw->Desk)
{
/* Don't transfer focus to windows on other desks */
SetFocusWindow(set_focus_to, True, FOCUS_SET_FORCE);
}
if (focus_is_focused(fw))
{
DeleteFocus(True);
}
return set_focus_to;
}
/*
*
* Moves focus to specified window; only to be called bay Focus and FlipFocus
*
*/
static void _activate_window_by_command(
F_CMD_ARGS, int is_focus_by_flip_focus_cmd)
{
int cx;
int cy;
Bool do_not_warp;
sftfwin_args_t sf_args;
FvwmWindow * const fw = exc->w.fw;
struct monitor *m;
memset(&sf_args, 0, sizeof(sf_args));
sf_args.do_allow_force_broadcast = 1;
sf_args.is_focus_by_flip_focus_cmd = is_focus_by_flip_focus_cmd;
sf_args.set_by = FOCUS_SET_BY_FUNCTION;
sf_args.client_entered = 0;
if (fw == NULL || !FP_DO_FOCUS_BY_FUNCTION(FW_FOCUS_POLICY(fw)))
{
UngrabEm(GRAB_NORMAL);
if (fw)
{
/* give the window a chance to take the focus itself */
sf_args.do_forbid_warp = 1;
sf_args.do_force = 0;
set_focus_to_fwin(FW_W(fw), fw, &sf_args);
}
return;
}
m = fw->m;
if (Scr.bo.do_debug_randr)
{
monitor_dump_state(m);
}
do_not_warp = StrEquals(PeekToken(action, NULL), "NoWarp");
if (!do_not_warp)
{
if (fw->Desk != m->virtual_scr.CurrentDesk)
{
goto_desk(fw->Desk, m);
}
if (IS_ICONIFIED(fw))
{
rectangle g;
Bool rc;
rc = get_visible_icon_title_geometry(fw, &g);
if (rc == False)
{
get_visible_icon_picture_geometry(fw, &g);
}
cx = g.x + g.width / 2;
cy = g.y + g.height / 2;
}
else
{
cx = fw->g.frame.x + fw->g.frame.width/2;
cy = fw->g.frame.y + fw->g.frame.height/2;
}
if (
cx < 0 || cx >= monitor_get_all_widths() ||
cy < 0 || cy >= monitor_get_all_heights())
{
int dx;
int dy;
dx = ((cx + m->virtual_scr.Vx) / monitor_get_all_widths()) *
monitor_get_all_widths();
dy = ((cy + m->virtual_scr.Vy) / monitor_get_all_heights()) *
monitor_get_all_heights();
MoveViewport(m, dx, dy, True);
}
#if 0 /* can not happen */
/* If the window is still not visible, make it visible! */
if (fw->g.frame.x + fw->g.frame.width < 0 ||
fw->g.frame.y + fw->g.frame.height < 0 ||
fw->g.frame.x >= Scr.MyDisplayWidth ||
fw->g.frame.y >= Scr.MyDisplayHeight)
{
frame_setup_window(
fw, 0, 0, fw->g.frame.width,
fw->g.frame.height, False);
if (
FP_DO_WARP_POINTER_ON_FOCUS_FUNC(
FW_FOCUS_POLICY(fw)))
{
FWarpPointerUpdateEvpos(
exc->x.elast, dpy, None, Scr.Root, 0,
0, 0, 0, 2, 2);
}
}
#endif
}
UngrabEm(GRAB_NORMAL);
{
FvwmWindow *sf;
sf = get_focus_window();
sf_args.do_forbid_warp = !!do_not_warp;
sf_args.do_force = 0;
sf_args.client_entered = 0;
set_focus_to_fwin(FW_W(fw), fw, &sf_args);
if (sf != get_focus_window())
{
/* Ignore EnterNotify event while we are waiting for
* this window to be focused. */
Scr.focus_in_pending_window = sf;
}
}
return;
}
static void _focus_grab_one_button(
FvwmWindow *fw, int button, int grab_buttons)
{
Bool do_grab;
do_grab = (grab_buttons & (1 << button));
if ((do_grab & (1 << button)) == (fw->grabbed_buttons & (1 << button)))
{
return;
}
if (do_grab)
{
XGrabButton(
dpy, button + 1, AnyModifier, FW_W_PARENT(fw), True,
ButtonPressMask, GrabModeSync, GrabModeAsync, None,
None);
/* Set window flags accordingly as we grab or ungrab. */
fw->grabbed_buttons |= (1 << button);
}
else
{
XUngrabButton(dpy, button + 1, AnyModifier, FW_W_PARENT(fw));
fw->grabbed_buttons &= ~(1 << button);
}
return;
}
/* ---------------------------- interface functions ------------------------ */
Bool focus_does_accept_input_focus(const FvwmWindow *fw)
{
return (!fw || !fw->wmhints ||
!(fw->wmhints->flags & InputHint) || fw->wmhints->input);
}
Bool focus_is_focused(const FvwmWindow *fw)
{
return (fw && fw == ScreenFocus);
}
Bool focus_query_click_to_raise(
FvwmWindow *fw, Bool is_focused, int context)
{
fpol_context_t *c;
if (is_focused)
{
c = &FP_DO_RAISE_FOCUSED_CLICK(FW_FOCUS_POLICY(fw));
}
else
{
c = &FP_DO_RAISE_UNFOCUSED_CLICK(FW_FOCUS_POLICY(fw));
}
return focus_get_fpol_context_flag(c, context);
}
Bool focus_query_click_to_focus(
FvwmWindow *fw, int context)
{
fpol_context_t *c;
c = &FP_DO_FOCUS_CLICK(FW_FOCUS_POLICY(fw));
return focus_get_fpol_context_flag(c, context);
}
/* Takes as input the window that wants the focus and the one that currently
* has the focus and returns if the new window should get it. */
Bool focus_query_open_grab_focus(FvwmWindow *fw, FvwmWindow *focus_win)
{
if (fw == NULL)
{
return False;
}
focus_win = get_focus_window();
if (focus_win != NULL &&
FP_DO_OVERRIDE_GRAB_FOCUS(FW_FOCUS_POLICY(focus_win)))
{
/* Don't steal the focus from the current window */
return False;
}
validate_transientfor(fw);
if (IS_TRANSIENT(fw) && FW_W_TRANSIENTFOR(fw) != Scr.Root)
{
if (focus_win != NULL &&
FP_DO_GRAB_FOCUS_TRANSIENT(FW_FOCUS_POLICY(fw)) &&
FW_W(focus_win) == FW_W_TRANSIENTFOR(fw))
{
/* it's a transient and its transientfor currently has
* focus. */
return True;
}
}
else
{
if (FP_DO_GRAB_FOCUS(FW_FOCUS_POLICY(fw)) &&
(focus_win == NULL ||
!FP_DO_OVERRIDE_GRAB_FOCUS(FW_FOCUS_POLICY(focus_win))))
{
return True;
}
}
return False;
}
/* Returns true if the focus has to be restored to a different window after
* unmapping. */
Bool focus_query_close_release_focus(const FvwmWindow *fw)
{
if (fw == NULL || fw != get_focus_window())
{
return False;
}
if (!IS_TRANSIENT(fw) &&
(FW_W_TRANSIENTFOR(fw) == Scr.Root ||
FP_DO_GRAB_FOCUS(FW_FOCUS_POLICY(fw))))
{
return True;
}
else if (IS_TRANSIENT(fw) &&
FP_DO_GRAB_FOCUS_TRANSIENT(FW_FOCUS_POLICY(fw)))
{
return True;
}
return False;
}
static void _focus_grab_buttons(FvwmWindow *fw, Bool client_entered)
{
int i;
Bool do_grab_window = False;
int grab_buttons;
if (fw == NULL || IS_SCHEDULED_FOR_DESTROY(fw) || !IS_MAPPED(fw))
{
/* It is pointless to grab buttons on dieing windows. Buttons
* can not be grabbed when the window is unmapped. */
return;
}
grab_buttons = Scr.buttons2grab;
do_grab_window = focus_query_grab_buttons(fw, client_entered);
if (do_grab_window == True)
{
grab_buttons |= FP_USE_MOUSE_BUTTONS(FW_FOCUS_POLICY(fw));
}
if (grab_buttons != fw->grabbed_buttons)
{
MyXGrabServer(dpy);
for (i = 0; i < NUMBER_OF_EXTENDED_MOUSE_BUTTONS; i++)
{
_focus_grab_one_button(fw, i, grab_buttons);
}
MyXUngrabServer (dpy);
}
return;
}
void focus_grab_buttons(FvwmWindow *fw)
{
_focus_grab_buttons(fw, False);
}
void focus_grab_buttons_client_entered(FvwmWindow *fw)
{
_focus_grab_buttons(fw, True);
}
void focus_grab_buttons_on_layer(int layer)
{
FvwmWindow *fw;
for (
fw = Scr.FvwmRoot.stack_next;
fw != &Scr.FvwmRoot && fw->layer >= layer;
fw = fw->stack_next)
{
if (fw->layer == layer)
{
focus_grab_buttons(fw);
}
}
return;
}
void focus_grab_buttons_all(void)
{
FvwmWindow *fw;
for (fw = Scr.FvwmRoot.next; fw != NULL; fw = fw->next)
{
focus_grab_buttons(fw);
}
return;
}
void _SetFocusWindow(
FvwmWindow *fw, Bool do_allow_force_broadcast,
fpol_set_focus_by_t set_by, Bool client_entered)
{
sftfwin_args_t sf_args;
memset(&sf_args, 0, sizeof(sf_args));
sf_args.do_allow_force_broadcast = !!do_allow_force_broadcast;
sf_args.is_focus_by_flip_focus_cmd = 0;
sf_args.do_forbid_warp = 0;
sf_args.do_force = 1;
sf_args.set_by = set_by;
if (client_entered)
{
sf_args.client_entered = 1;
}
else
{
sf_args.client_entered = 0;
}
set_focus_to_fwin(FW_W(fw), fw, &sf_args);
return;
}
void _ReturnFocusWindow(FvwmWindow *fw)
{
sftfwin_args_t sf_args;
memset(&sf_args, 0, sizeof(sf_args));
sf_args.do_allow_force_broadcast = 1;
sf_args.is_focus_by_flip_focus_cmd = 0;
sf_args.do_forbid_warp = 1;
sf_args.client_entered = 0;
sf_args.do_force = 0;
sf_args.set_by = FOCUS_SET_FORCE;
set_focus_to_fwin(FW_W(fw), fw, &sf_args);
return;
}
void _DeleteFocus(Bool do_allow_force_broadcast)
{
sftfwin_args_t sf_args;
memset(&sf_args, 0, sizeof(sf_args));
sf_args.do_allow_force_broadcast = !!do_allow_force_broadcast;
sf_args.is_focus_by_flip_focus_cmd = 0;
sf_args.do_forbid_warp = 0;
sf_args.client_entered = 0;
sf_args.do_force = 0;
sf_args.set_by = FOCUS_SET_FORCE;
set_focus_to_fwin(Scr.NoFocusWin, NULL, &sf_args);
return;
}
void _ForceDeleteFocus(void)
{
sftfwin_args_t sf_args;
memset(&sf_args, 0, sizeof(sf_args));
sf_args.do_allow_force_broadcast = 1;
sf_args.is_focus_by_flip_focus_cmd = 0;
sf_args.do_forbid_warp = 0;
sf_args.client_entered = 0;
sf_args.do_force = 1;
sf_args.set_by = FOCUS_SET_FORCE;