-
-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathmodule_interface.c
More file actions
1057 lines (932 loc) · 24.1 KB
/
module_interface.c
File metadata and controls
1057 lines (932 loc) · 24.1 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/>
*/
/*
*
* code for talking with fvwm modules.
*
*/
#include "config.h"
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
#include "libs/log.h"
#include "libs/ftime.h"
#include "libs/fvwmlib.h"
#include "libs/ColorUtils.h"
#include "libs/Parse.h"
#include "libs/Strings.h"
#include "libs/wild.h"
#include "libs/FEvent.h"
#include "fvwm.h"
#include "externs.h"
#include "cmdparser.h"
#include "functions.h"
#include "bindings.h"
#include "misc.h"
#include "screen.h"
#include "module_interface.h"
#include "module_list.h"
#include "events.h"
#include "geometry.h"
#include "libs/fvwmsignal.h"
#include "decorations.h"
#include "ewmh.h"
#include "commands.h"
/* A queue of commands from the modules */
static fqueue cqueue = FQUEUE_INIT;
static const unsigned long dummy = 0;
static void send_monitor_info(fmodule *);
static void send_one_windowlist_batch(fmodule *, struct monitor *, int);
static unsigned long *
make_vpacket(unsigned long *body, unsigned long event_type,
unsigned long num, va_list ap)
{
unsigned long *bp = body;
/* truncate long packets */
if (num > FvwmPacketMaxSize)
{
num = FvwmPacketMaxSize;
}
*(bp++) = START_FLAG;
*(bp++) = event_type;
*(bp++) = num+FvwmPacketHeaderSize;
*(bp++) = fev_get_evtime();
for (; num > 0; --num)
{
*(bp++) = va_arg(ap, unsigned long);
}
return body;
}
/*
RBW - 04/16/1999 - new packet builder for GSFR --
Arguments are pairs of lengths and argument data pointers.
RBW - 05/01/2000 -
A length of zero means that an int is being passed which
must be stored in the packet as an unsigned long. This is
a special hack to accommodate the old CONFIGARGS
technique of sending the args for the M_CONFIGURE_WINDOW
packet.
*/
static unsigned long
make_new_vpacket(unsigned char *body, unsigned long event_type,
unsigned long num, va_list ap)
{
long arglen;
unsigned long addlen;
unsigned long bodylen = 0;
unsigned long *bp = (unsigned long *)body;
unsigned long *bp1 = bp;
unsigned long plen = 0;
unsigned long dlen;
*(bp++) = START_FLAG;
*(bp++) = event_type;
/* Skip length field, we don't know it yet. */
bp++;
*(bp++) = fev_get_evtime();
for (; num > 0; --num)
{
arglen = va_arg(ap, long);
if (arglen <= 0)
{
if (arglen == 0)
{
arglen = -sizeof(int);
}
addlen = sizeof(unsigned long);
}
else
{
addlen = arglen;
}
bodylen += addlen;
if (bodylen >= FvwmPacketMaxSize_byte)
{
fvwm_debug(__func__,
"packet too long %ld %ld", (long)bodylen,
(long)FvwmPacketMaxSize_byte);
break;
}
if (arglen > 0)
{
register char *tmp = (char *)bp;
memcpy(tmp, va_arg(ap, char *), arglen);
tmp += arglen;
bp = (unsigned long *)tmp;
}
else if (arglen == 0 || arglen == -sizeof(int))
{
int *tmp;
tmp = va_arg(ap, int *);
*bp = (unsigned long) *tmp;
bp++;
}
else if (arglen == -sizeof(long))
{
unsigned long *tmp;
tmp = va_arg(ap, unsigned long *);
*bp = (unsigned long) *tmp;
bp++;
}
else if (arglen == -sizeof(short))
{
short *tmp;
tmp = va_arg(ap, short *);
*bp = (unsigned long) *tmp;
bp++;
}
else
{
fvwm_debug(__func__,
"can not handle arglen %ld, please contact"
" fvwm-workers@fvwm.org. aborting...",
arglen);
abort();
}
}
/*
Round up to a long word boundary. Most of the module interface
still thinks in terms of an array of longs, so let's humor it.
*/
dlen = (unsigned long) ((unsigned char *)bp - body);
plen = ((dlen + (sizeof(long) - 1)) / sizeof(long)) * sizeof(long);
if (plen > dlen)
{
/* initialise padding */
memset(body + dlen, 0, plen - dlen);
}
*(((unsigned long*)bp1)+2) = (plen / (sizeof(unsigned long)));
return plen;
}
void SendPacket(
fmodule *module, unsigned long event_type, unsigned long num_datum,
...)
{
unsigned long body[FvwmPacketMaxSize];
va_list ap;
va_start(ap, num_datum);
make_vpacket(body, event_type, num_datum, ap);
va_end(ap);
PositiveWrite(
module, body,
(num_datum+FvwmPacketHeaderSize)*sizeof(body[0]));
return;
}
void BroadcastPacket(unsigned long event_type, unsigned long num_datum, ...)
{
unsigned long body[FvwmPacketMaxSize];
va_list ap;
fmodule_list_itr moditr;
fmodule *module;
va_start(ap,num_datum);
make_vpacket(body, event_type, num_datum, ap);
va_end(ap);
module_list_itr_init(&moditr);
while ( (module = module_list_itr_next(&moditr)) != NULL)
{
PositiveWrite(
module, body,
(num_datum+FvwmPacketHeaderSize)*sizeof(body[0]));
}
return;
}
/*
RBW - 04/16/1999 - new style packet senders for GSFR --
*/
static void SendNewPacket(
fmodule *module, unsigned long event_type, unsigned long num_datum,
...)
{
unsigned char body[FvwmPacketMaxSize_byte];
va_list ap;
unsigned long plen;
va_start(ap,num_datum);
plen = make_new_vpacket(body, event_type, num_datum, ap);
va_end(ap);
PositiveWrite(module, (void *) &body, plen);
return;
}
static void BroadcastNewPacket(unsigned long event_type,
unsigned long num_datum, ...)
{
unsigned char body[FvwmPacketMaxSize_byte];
va_list ap;
fmodule_list_itr moditr;
fmodule *module;
unsigned long plen;
va_start(ap,num_datum);
plen = make_new_vpacket(body, event_type, num_datum, ap);
va_end(ap);
module_list_itr_init(&moditr);
while ( (module = module_list_itr_next(&moditr)) != NULL)
{
PositiveWrite(module, (void *) &body, plen);
}
return;
}
action_flags *_get_allowed_actions(const FvwmWindow *fw)
{
static action_flags act;
act.is_movable = is_function_allowed(
F_MOVE, NULL, fw, RQORIG_PROGRAM_US, False);
act.is_deletable = is_function_allowed(
F_DELETE, NULL, fw, RQORIG_PROGRAM_US, False);
act.is_destroyable = is_function_allowed(
F_DESTROY, NULL, fw, RQORIG_PROGRAM_US, False);
act.is_closable = is_function_allowed(
F_CLOSE, NULL, fw, RQORIG_PROGRAM_US, False);
act.is_maximizable = is_function_allowed(
F_MAXIMIZE, NULL, fw, RQORIG_PROGRAM_US, False);
act.is_resizable = is_function_allowed(
F_RESIZE, NULL, fw, RQORIG_PROGRAM_US, False);
act.is_iconifiable = is_function_allowed(
F_ICONIFY, NULL, fw, RQORIG_PROGRAM_US, False);
return &act;
}
/*
RBW - 04/16/1999 - new version for GSFR --
- args are now pairs:
- length of arg data
- pointer to arg data
- number of arguments is the number of length/pointer pairs.
- the 9th field, where flags used to be, is temporarily left
as a dummy to preserve alignment of the other fields in the
old packet: we should drop this before the next release.
*/
#define CONFIGARGS(_fw) 34, \
(unsigned long)(-sizeof(Window)), \
&FW_W(*(_fw)), \
(unsigned long)(-sizeof(Window)), \
&FW_W_FRAME(*(_fw)), \
(unsigned long)(-sizeof(void *)), \
&(_fw), \
(unsigned long)(0), \
&(*(_fw))->g.frame.x, \
(unsigned long)(0), \
&(*(_fw))->g.frame.y, \
(unsigned long)(0), \
&(*(_fw))->g.frame.width, \
(unsigned long)(0), \
&(*(_fw))->g.frame.height, \
(unsigned long)(0), \
&(*(_fw))->Desk, \
(unsigned long)(0), \
&(*(_fw))->m->si->rr_output, \
(unsigned long)(0), \
&(*(_fw))->layer, \
(unsigned long)(0), \
&(*(_fw))->hints.base_width, \
(unsigned long)(0), \
&(*(_fw))->hints.base_height, \
(unsigned long)(0), \
&(*(_fw))->hints.width_inc, \
(unsigned long)(0), \
&(*(_fw))->hints.height_inc, \
(unsigned long)(0), \
&(*(_fw))->orig_hints.width_inc, \
(unsigned long)(0), \
&(*(_fw))->orig_hints.height_inc, \
(unsigned long)(0), \
&(*(_fw))->hints.min_width, \
(unsigned long)(0), \
&(*(_fw))->hints.min_height, \
(unsigned long)(0), \
&(*(_fw))->hints.max_width, \
(unsigned long)(0), \
&(*(_fw))->hints.max_height, \
(unsigned long)(-sizeof(Window)), \
&FW_W_ICON_TITLE(*(_fw)), \
(unsigned long)(-sizeof(Window)), \
&FW_W_ICON_PIXMAP(*(_fw)), \
(unsigned long)(0), \
&(*(_fw))->hints.win_gravity, \
(unsigned long)(-sizeof(Pixel)), \
&(*(_fw))->colors.fore, \
(unsigned long)(-sizeof(Pixel)), \
&(*(_fw))->colors.back, \
(unsigned long)(0), \
&(*(_fw))->ewmh_hint_layer, \
(unsigned long)(sizeof(unsigned long)), \
&(*(_fw))->ewmh_hint_desktop, \
(unsigned long)(0), \
&(*(_fw))->ewmh_window_type, \
(unsigned long)(sizeof(short)), \
&(*(_fw))->title_thickness, \
(unsigned long)(sizeof(short)), \
&(*(_fw))->boundary_width, \
(unsigned long)(sizeof(short)), \
&dummy, \
(unsigned long)(sizeof(short)), \
&dummy, \
(unsigned long)(sizeof((*(_fw))->flags)), \
&(*(_fw))->flags, \
(unsigned long)(sizeof(action_flags)), \
_get_allowed_actions((*(_fw)))
void SendConfig(fmodule *module, unsigned long event_type, const FvwmWindow *t)
{
const FvwmWindow **t1 = &t;
/* RBW- SendPacket(module, event_type, CONFIGARGS(t)); */
SendNewPacket(module, event_type, CONFIGARGS(t1));
return;
}
void BroadcastConfig(unsigned long event_type, const FvwmWindow *t)
{
const FvwmWindow **t1 = &t;
/* RBW- BroadcastPacket(event_type, CONFIGARGS(t)); */
BroadcastNewPacket(event_type, CONFIGARGS(t1));
return;
}
static unsigned long *make_named_packet(
int *len, unsigned long event_type, const char *name, int num, ...)
{
unsigned long *body;
va_list ap;
/* Packet is the header plus the items plus enough items to hold the
* name string. */
*len = FvwmPacketHeaderSize + num +
(strlen(name) / sizeof(unsigned long)) + 1;
/* truncate long packets */
if (*len > FvwmPacketMaxSize)
{
*len = FvwmPacketMaxSize;
}
body = fxmalloc(*len * sizeof(unsigned long));
/* Zero out end of memory to avoid uninit memory access. */
body[*len-1] = 0;
va_start(ap, num);
make_vpacket(body, event_type, num, ap);
va_end(ap);
strncpy((char *)&body[FvwmPacketHeaderSize+num], name,
(*len - FvwmPacketHeaderSize - num)*sizeof(unsigned long) - 1);
body[2] = *len;
return (body);
}
void SendName(
fmodule *module, unsigned long event_type,
unsigned long data1,unsigned long data2, unsigned long data3,
const char *name)
{
unsigned long *body;
int l;
if (name == NULL)
{
return;
}
body = make_named_packet(&l, event_type, name, 3, data1, data2, data3);
PositiveWrite(module, body, l*sizeof(unsigned long));
free(body);
return;
}
void BroadcastName(
unsigned long event_type,
unsigned long data1, unsigned long data2, unsigned long data3,
const char *name)
{
unsigned long *body;
int l;
fmodule_list_itr moditr;
fmodule *module;
if (name == NULL)
{
return;
}
body = make_named_packet(&l, event_type, name, 3, data1, data2, data3);
module_list_itr_init(&moditr);
while ( (module = module_list_itr_next(&moditr)) != NULL)
{
PositiveWrite(module, body, l*sizeof(unsigned long));
}
free(body);
return;
}
void BroadcastDesktopConfiguration(fmodule *send)
{
char name[256];
snprintf(name, sizeof(name), "DesktopConfiguration %d %d",
monitor_mode, is_tracking_shared);
SendName(send, M_CONFIG_INFO, 0, 0, 0, name);
}
static
void send_monitor_info(fmodule *send)
{
struct monitor *m;
boundingbox r;
const char *m_info;
char *name;
m_info = "Monitor %s %d %d %d %d %d %d %d %d %d %d %d %d %d %d";
RB_FOREACH(m, monitors, &monitor_q) {
r = get_ewmhc_boundingbox(m);
xasprintf(&name, m_info, m->si->name, m->flags,
m->dx, m->dy, m->virtual_scr.Vx,
m->virtual_scr.Vy, m->virtual_scr.VxMax,
m->virtual_scr.VyMax, m->virtual_scr.CurrentDesk,
monitor_get_all_widths(), monitor_get_all_heights(),
r.left, r.right, r.top, r.bottom
);
SendName(send, M_CONFIG_INFO, 0, 0, 0, name);
free(name);
}
}
void BroadcastMonitorList(fmodule *this)
{
char action[256];
struct monitor *m;
fmodule_list_itr moditr;
fmodule *module;
module_list_itr_init(&moditr);
if (this != NULL) {
/*
* We've been requested to send this information to a specific
* module only.
*/
send_monitor_info(this);
BroadcastDesktopConfiguration(this);
goto out;
}
while ((module = module_list_itr_next(&moditr)) != NULL) {
send_monitor_info(module);
BroadcastDesktopConfiguration(module);
}
out:
/* Reissue the DesktopSize command here, rather than sending
* down the DesktopSize -- we want FvwmPager in particular to
* react to a M_NEW_PAGE event, which DesktopSize will do; and
* this avoids duplication in FvwmPager as a result.
*/
/* Every monitor will have the same dx/dy values, so just take
* the fist entry in our list.
*/
m = RB_MIN(monitors, &monitor_q);
snprintf(action, sizeof(action), "DesktopSize %dx%d", m->dx, m->dy);
execute_function_override_window(NULL, NULL, action, NULL, 0, NULL);
}
void BroadcastWindowIconNames(FvwmWindow *fw, Bool window, Bool icon)
{
if (window)
{
BroadcastName(
M_WINDOW_NAME, FW_W(fw), FW_W_FRAME(fw),
(unsigned long)fw, fw->name.name);
BroadcastName(
M_VISIBLE_NAME, FW_W(fw), FW_W_FRAME(fw),
(unsigned long)fw, fw->visible_name);
}
if (icon)
{
BroadcastName(
M_ICON_NAME, FW_W(fw), FW_W_FRAME(fw),
(unsigned long)fw, fw->icon_name.name);
BroadcastName(
MX_VISIBLE_ICON_NAME, FW_W(fw), FW_W_FRAME(fw),
(unsigned long)fw, fw->visible_icon_name);
}
return;
}
void SendFvwmPicture(
fmodule *module, unsigned long event_type, unsigned long data1,
unsigned long data2, unsigned long data3, FvwmPicture *picture,
char *name)
{
unsigned long *body;
unsigned long
data4 = 0, data5 = 0, data6 = 0,
data7 = 0, data8 = 0, data9 = 0;
int l;
if (!FMiniIconsSupported)
{
return;
}
if ((name == NULL) || (event_type != M_MINI_ICON))
{
return;
}
if (picture != NULL)
{
data4 = picture->width;
data5 = picture->height;
data6 = picture->depth;
data7 = picture->picture;
data8 = picture->mask;
data9 = picture->alpha;
}
body = make_named_packet(
&l, event_type, name, 9, data1, data2, data3, data4, data5,
data6, data7, data8, data9);
PositiveWrite(module, body, l*sizeof(unsigned long));
free(body);
return;
}
void BroadcastFvwmPicture(
unsigned long event_type, unsigned long data1, unsigned long data2,
unsigned long data3, FvwmPicture *picture, char *name)
{
unsigned long *body;
unsigned long data4, data5, data6, data7, data8, data9;
int l;
fmodule_list_itr moditr;
fmodule *module;
if (!FMiniIconsSupported)
{
return;
}
if (picture != NULL)
{
data4 = picture->width;
data5 = picture->height;
data6 = picture->depth;
data7 = picture->picture;
data8 = picture->mask;
data9 = picture->alpha;
}
else
{
data4 = 0;
data5 = 0;
data6 = 0;
data7 = 0;
data8 = 0;
data9 = 0;
}
body = make_named_packet(
&l, event_type, name, 9, data1, data2, data3, data4, data5,
data6, data7, data8, data9);
module_list_itr_init(&moditr);
while ( (module = module_list_itr_next(&moditr)) != NULL)
{
PositiveWrite(module, body, l*sizeof(unsigned long));
}
free(body);
return;
}
/*
* Reads a colorset command from a module and broadcasts it back out
*/
void BroadcastColorset(int n)
{
fmodule_list_itr moditr;
fmodule *module;
char *buf;
buf = DumpColorset(n, &Colorset[n]);
module_list_itr_init(&moditr);
while ( (module = module_list_itr_next(&moditr)) != NULL)
{
SendName(module, M_CONFIG_INFO, 0, 0, 0, buf);
}
return;
}
/*
* Broadcasts a string to all modules as M_CONFIG_INFO.
*/
void BroadcastPropertyChange(
unsigned long argument, unsigned long data1, unsigned long data2,
char *string)
{
fmodule_list_itr moditr;
fmodule *module;
module_list_itr_init(&moditr);
while ( (module = module_list_itr_next(&moditr)) != NULL)
{
SendName(module, MX_PROPERTY_CHANGE, argument,
data1, data2, string);
}
return;
}
/*
* Broadcasts a string to all modules as M_CONFIG_INFO.
*/
void BroadcastConfigInfoString(char *string)
{
fmodule_list_itr moditr;
fmodule *module;
module_list_itr_init(&moditr);
while ( (module = module_list_itr_next(&moditr)) != NULL)
{
SendName(module, M_CONFIG_INFO, 0, 0, 0, string);
}
return;
}
/*
* Broadcasts the ignored modifiers to all modules as M_CONFIG_INFO.
*/
void broadcast_ignore_modifiers(void)
{
char msg[32];
snprintf(msg, sizeof(msg), "IgnoreModifiers %d", GetUnusedModifiers());
BroadcastConfigInfoString(msg);
return;
}
/* run the input command as if it cames from a button press or release */
void module_input_execute(struct fmodule_input *input)
{
XEvent e;
const exec_context_t *exc;
exec_context_changes_t ecc;
int flags;
memset(&e, 0, sizeof(e));
if (XFindContext(dpy, input->window, FvwmContext,
(caddr_t *)&ecc.w.fw) == XCNOENT)
{
ecc.w.fw = NULL;
input->window = None;
}
/* Query the pointer, the pager-drag-out feature doesn't work properly.
* This is OK now that the Pager uses "Move pointer"
* A real fix would be for the modules to pass the button press coords
*/
FQueryPointer(
dpy, Scr.Root, &JunkRoot, &JunkChild, &JunkX,&JunkY,
&e.xbutton.x_root, &e.xbutton.y_root, &e.xbutton.state);
e.xbutton.window = input->window;
e.xbutton.subwindow = None;
e.xbutton.button = 1;
/* If a module does XUngrabPointer(), it can now get proper Popups */
if (StrEquals(input->command, "popup"))
{
e.xbutton.type = ButtonPress;
e.xbutton.state |= Button1Mask;
}
else
{
e.xbutton.type = ButtonRelease;
e.xbutton.state &= (~(Button1Mask));
}
e.xbutton.x = 0;
e.xbutton.y = 0;
fev_fake_event(&e);
ecc.type = EXCT_MODULE;
ecc.w.w = input->window;
flags = (input->window == None) ? 0 : FUNC_DONT_DEFER;
ecc.w.wcontext = GetContext(NULL, ecc.w.fw, &e, &(input->window));
ecc.x.etrigger = &e;
ecc.m.module = input->module;
exc = exc_create_context(
&ecc, ECC_TYPE | ECC_ETRIGGER | ECC_FW | ECC_W | ECC_WCONTEXT |
ECC_MODULE);
execute_function(NULL, exc, input->command, NULL, flags);
exc_destroy_context(exc);
module_input_discard(input);
return;
}
/* enqueue a module command on the command queue to be executed later */
void module_input_enqueue(struct fmodule_input *input)
{
if (input == NULL)
{
return;
}
fqueue_add_at_end(&cqueue, (void*)input);
}
/*
*
* Procedure:
* ExecuteCommandQueue - runs command from the module command queue
* This may be called recursively if a module command runs a function
* that does a Wait, so it must be re-entrant
*
*/
void ExecuteCommandQueue(void)
{
fmodule_input *input;
while (fqueue_get_first(&cqueue, (void **)&input) == 1)
{
/* remove from queue */
fqueue_remove_or_operate_from_front(
&cqueue, NULL, NULL, NULL, NULL);
/* execute and destroy */
if (input->command)
{
module_input_execute(input);
}
else
{
module_input_discard(input);
}
}
return;
}
/*
** send an arbitrary string to all instances of a module
*/
void CMD_SendToModule(F_CMD_ARGS)
{
char *name,*str;
unsigned long data0, data1, data2;
fmodule_list_itr moditr;
fmodule *module;
FvwmWindow * const fw = exc->w.fw;
/* FIXME: Without this, popup menus can't be implemented properly in
* modules. Olivier: Why ? */
/* UngrabEm(); */
if (!action)
{
return;
}
str = GetNextToken(action, &name);
if (!name)
{
return;
}
if (fw)
{
/* Modules may need to know which window this applies to */
data0 = FW_W(fw);
data1 = FW_W_FRAME(fw);
data2 = (unsigned long)fw;
}
else
{
data0 = 0;
data1 = 0;
data2 = 0;
}
module_list_itr_init(&moditr);
while ( (module = module_list_itr_next(&moditr)) != NULL)
{
if (
(MOD_NAME(module) != NULL &&
matchWildcards(name,MOD_NAME(module))) ||
(MOD_ALIAS(module) &&
matchWildcards(name, MOD_ALIAS(module))))
{
SendName(module,M_STRING,data0,data1,data2,str);
FlushMessageQueue(module);
}
}
free(name);
return;
}
/*
** send an arbitrary string back to the calling module
*/
void CMD_Send_Reply(F_CMD_ARGS)
{
unsigned long data0, data1, data2;
fmodule *module = exc->m.module;
FvwmWindow * const fw = exc->w.fw;
if (module == NULL)
{
return;
}
if (!action)
{
return;
}
if (fw)
{
/* Modules may need to know which window this applies to */
data0 = FW_W(fw);
data1 = FW_W_FRAME(fw);
data2 = (unsigned long)fw;
}
else
{
data0 = 0;
data1 = 0;
data2 = 0;
}
SendName(module, MX_REPLY, data0, data1, data2, action);
FlushMessageQueue(module);
return;
}
static void
send_one_windowlist_batch(fmodule *mod, struct monitor *m, int force)
{
FvwmWindow *t;
SendPacket(mod, M_NEW_DESK, 2, (long)m->virtual_scr.CurrentDesk,
(long)m->si->rr_output);
SendPacket(mod, M_NEW_PAGE, 8, (long)m->virtual_scr.Vx,
(long)m->virtual_scr.Vy,
(long)m->virtual_scr.CurrentDesk,
(long) monitor_get_all_widths(),
(long) monitor_get_all_heights(),
(long)((m->virtual_scr.VxMax / monitor_get_all_widths()) + 1),
(long)((m->virtual_scr.VyMax / monitor_get_all_heights()) + 1),
(long)m->si->rr_output);
if (Scr.Hilite != NULL)
{
SendPacket(mod, M_FOCUS_CHANGE, 5, (long)FW_W(Scr.Hilite),
(long)FW_W_FRAME(Scr.Hilite), (unsigned long)True,
(long)Scr.Hilite->hicolors.fore,
(long)Scr.Hilite->hicolors.back);
}
else
{
SendPacket(mod, M_FOCUS_CHANGE, 5, 0, 0, (unsigned long)True,
(long)Colorset[0].fg, (long)Colorset[0].bg);
}
if (Scr.DefaultIcon != NULL)
{
SendName(mod, M_DEFAULTICON, 0, 0, 0, Scr.DefaultIcon);
}
for (t = Scr.FvwmRoot.next; t != NULL; t = t->next)
{
if ((monitor_mode == MONITOR_TRACKING_M || force) && t->m != m)
continue;
SendConfig(mod,M_CONFIGURE_WINDOW,t);
SendName(
mod, M_WINDOW_NAME, FW_W(t), FW_W_FRAME(t),
(unsigned long)t, t->name.name);
SendName(
mod, M_ICON_NAME, FW_W(t), FW_W_FRAME(t),
(unsigned long)t, t->icon_name.name);
SendName(
mod, M_VISIBLE_NAME, FW_W(t), FW_W_FRAME(t),
(unsigned long)t, t->visible_name);
SendName(
mod, MX_VISIBLE_ICON_NAME, FW_W(t), FW_W_FRAME(t),
(unsigned long)t,t->visible_icon_name);
if (t->icon_bitmap_file != NULL
&& t->icon_bitmap_file != Scr.DefaultIcon)
{
SendName(
mod, M_ICON_FILE, FW_W(t), FW_W_FRAME(t),
(unsigned long)t, t->icon_bitmap_file);
}
SendName(
mod, M_RES_CLASS, FW_W(t), FW_W_FRAME(t),
(unsigned long)t, t->class.res_class);
SendName(
mod, M_RES_NAME, FW_W(t), FW_W_FRAME(t),
(unsigned long)t, t->class.res_name);
if (IS_ICONIFIED(t) && !IS_ICON_UNMAPPED(t))
{
rectangle r;
Bool rc;
rc = get_visible_icon_geometry(t, &r);
if (rc == True)
{
SendPacket(mod, M_ICONIFY, 7, (long)FW_W(t),
(long)FW_W_FRAME(t), (unsigned long)t,
(long)r.x, (long)r.y,
(long)r.width, (long)r.height);
}
}
if ((IS_ICONIFIED(t))&&(IS_ICON_UNMAPPED(t)))
{
SendPacket(mod, M_ICONIFY, 7, (long)FW_W(t),
(long)FW_W_FRAME(t), (unsigned long)t,
(long)0, (long)0, (long)0, (long)0);
}
if (FMiniIconsSupported && t->mini_icon != NULL)