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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094 | /* Croma window types/properties demo app */
/*
* Copyright (C) 2002 Havoc Pennington
*
* 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 St, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#include <ctk/ctk.h>
#include <cdk/cdkx.h>
#include <X11/Xatom.h>
#include <unistd.h>
static void
do_appwindow (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
static gboolean aspect_on;
static void
set_cdk_window_struts (CdkWindow *window,
int left,
int right,
int top,
int bottom)
{
long vals[12];
vals[0] = left;
vals[1] = right;
vals[2] = top;
vals[3] = bottom;
vals[4] = 000;
vals[5] = 400;
vals[6] = 200;
vals[7] = 600;
vals[8] = 76;
vals[9] = 676;
vals[10] = 200;
vals[11] = 800;
XChangeProperty (CDK_WINDOW_XDISPLAY (window),
CDK_WINDOW_XID (window),
XInternAtom (CDK_WINDOW_XDISPLAY (window),
"_NET_WM_STRUT_PARTIAL", False),
XA_CARDINAL, 32, PropModeReplace,
(guchar *)vals, 12);
}
static void
on_realize_set_struts (CtkWindow *window,
gpointer data)
{
CtkWidget *widget;
int left;
int right;
int top;
int bottom;
widget = CTK_WIDGET (window);
g_return_if_fail (ctk_widget_get_realized (widget));
left = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (window), "meta-strut-left"));
right = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (window), "meta-strut-right"));
top = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (window), "meta-strut-top"));
bottom = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (window), "meta-strut-bottom"));
set_cdk_window_struts (ctk_widget_get_window (widget),
left, right, top, bottom);
}
static void
set_ctk_window_struts (CtkWidget *window,
int left,
int right,
int top,
int bottom)
{
CtkWidget *widget;
widget = CTK_WIDGET (window);
g_object_set_data (G_OBJECT (window), "meta-strut-left",
GINT_TO_POINTER (left));
g_object_set_data (G_OBJECT (window), "meta-strut-right",
GINT_TO_POINTER (right));
g_object_set_data (G_OBJECT (window), "meta-strut-top",
GINT_TO_POINTER (top));
g_object_set_data (G_OBJECT (window), "meta-strut-bottom",
GINT_TO_POINTER (bottom));
g_signal_handlers_disconnect_by_func (G_OBJECT (window),
on_realize_set_struts,
NULL);
g_signal_connect_after (G_OBJECT (window),
"realize",
G_CALLBACK (on_realize_set_struts),
NULL);
if (ctk_widget_get_realized (widget))
set_cdk_window_struts (ctk_widget_get_window (widget),
left, right, top, bottom);
}
static void
set_cdk_window_type (CdkWindow *window,
const char *type)
{
Atom atoms[2] = { None, None };
atoms[0] = XInternAtom (CDK_WINDOW_XDISPLAY (window),
type, False);
XChangeProperty (CDK_WINDOW_XDISPLAY (window),
CDK_WINDOW_XID (window),
XInternAtom (CDK_WINDOW_XDISPLAY (window), "_NET_WM_WINDOW_TYPE", False),
XA_ATOM, 32, PropModeReplace,
(guchar *)atoms,
1);
}
static void
on_realize_set_type (CtkWindow *window,
gpointer data)
{
const char *type;
g_return_if_fail (ctk_widget_get_realized (CTK_WIDGET (window)));
type = g_object_get_data (G_OBJECT (window), "meta-window-type");
g_return_if_fail (type != NULL);
set_cdk_window_type (ctk_widget_get_window (CTK_WIDGET (window)),
type);
}
static void
set_ctk_window_type (CtkWindow *window,
const char *type)
{
CtkWidget *widget;
widget = CTK_WIDGET (window);
g_object_set_data (G_OBJECT (window), "meta-window-type", (char*) type);
g_signal_handlers_disconnect_by_func (G_OBJECT (window),
on_realize_set_type,
NULL);
g_signal_connect_after (G_OBJECT (window),
"realize",
G_CALLBACK (on_realize_set_type),
NULL);
if (ctk_widget_get_realized (widget))
set_cdk_window_type (ctk_widget_get_window (widget),
type);
}
static void
set_cdk_window_border_only (CdkWindow *window)
{
cdk_window_set_decorations (window, CDK_DECOR_BORDER);
}
static void
on_realize_set_border_only (CtkWindow *window,
gpointer data)
{
CtkWidget *widget;
widget = CTK_WIDGET (window);
g_return_if_fail (ctk_widget_get_realized (widget));
set_cdk_window_border_only (ctk_widget_get_window (widget));
}
static void
set_ctk_window_border_only (CtkWindow *window)
{
CtkWidget *widget;
widget = CTK_WIDGET (window);
g_signal_handlers_disconnect_by_func (G_OBJECT (window),
on_realize_set_border_only,
NULL);
g_signal_connect_after (G_OBJECT (window),
"realize",
G_CALLBACK (on_realize_set_border_only),
NULL);
if (ctk_widget_get_realized (widget))
set_cdk_window_border_only (ctk_widget_get_window (widget));
}
int
main (int argc, char **argv)
{
GdkPixbuf *pixbuf;
GError *err;
ctk_init (&argc, &argv);
err = NULL;
pixbuf = gdk_pixbuf_new_from_file (CROMA_ICON_DIR"/croma-window-demo.png",
&err);
if (pixbuf)
{
GList *list;
list = g_list_prepend (NULL, pixbuf);
ctk_window_set_default_icon_list (list);
g_list_free (list);
g_object_unref (G_OBJECT (pixbuf));
}
else
{
g_printerr ("Could not load icon: %s\n", err->message);
g_error_free (err);
}
do_appwindow (NULL, NULL, NULL);
ctk_main ();
return 0;
}
static void
response_cb (CtkDialog *dialog,
int response_id,
void *data);
static void
make_dialog (CtkWidget *parent,
int depth)
{
CtkWidget *dialog;
char *str;
dialog = ctk_message_dialog_new (parent ? CTK_WINDOW (parent) : NULL,
CTK_DIALOG_DESTROY_WITH_PARENT,
CTK_MESSAGE_INFO,
CTK_BUTTONS_CLOSE,
parent ? "Here is a dialog %d" :
"Here is a dialog %d with no transient parent",
depth);
str = g_strdup_printf ("%d dialog", depth);
ctk_window_set_title (CTK_WINDOW (dialog), str);
g_free (str);
ctk_dialog_add_button (CTK_DIALOG (dialog),
"Open child dialog",
CTK_RESPONSE_ACCEPT);
/* Close dialog on user response */
g_signal_connect (G_OBJECT (dialog),
"response",
G_CALLBACK (response_cb),
NULL);
g_object_set_data (G_OBJECT (dialog), "depth",
GINT_TO_POINTER (depth));
ctk_widget_show (dialog);
}
static void
response_cb (CtkDialog *dialog,
int response_id,
void *data)
{
switch (response_id)
{
case CTK_RESPONSE_ACCEPT:
make_dialog (CTK_WIDGET (dialog),
GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dialog),
"depth")) + 1);
break;
default:
ctk_widget_destroy (CTK_WIDGET (dialog));
break;
}
}
static void
dialog_cb (GSimpleAction *action,
GVariant *parameter,
gpointer callback_data)
{
make_dialog (CTK_WIDGET (callback_data), 1);
}
static void
modal_dialog_cb (GSimpleAction *action,
GVariant *parameter,
gpointer callback_data)
{
CtkWidget *dialog;
dialog = ctk_message_dialog_new (CTK_WINDOW (callback_data),
CTK_DIALOG_DESTROY_WITH_PARENT,
CTK_MESSAGE_INFO,
CTK_BUTTONS_CLOSE,
"Here is a MODAL dialog");
set_ctk_window_type (CTK_WINDOW (dialog), "_NET_WM_WINDOW_TYPE_MODAL_DIALOG");
ctk_dialog_run (CTK_DIALOG (dialog));
ctk_widget_destroy (dialog);
}
static void
no_parent_dialog_cb (GSimpleAction *action,
GVariant *parameter,
gpointer callback_data)
{
make_dialog (NULL, 1);
}
static void
utility_cb (GSimpleAction *action,
GVariant *parameter,
gpointer callback_data)
{
CtkWidget *window;
CtkWidget *vbox;
CtkWidget *button;
window = ctk_window_new (CTK_WINDOW_TOPLEVEL);
set_ctk_window_type (CTK_WINDOW (window), "_NET_WM_WINDOW_TYPE_UTILITY");
ctk_window_set_title (CTK_WINDOW (window), "Utility");
ctk_window_set_transient_for (CTK_WINDOW (window), CTK_WINDOW (callback_data));
vbox = ctk_box_new (CTK_ORIENTATION_VERTICAL, 0);
ctk_container_add (CTK_CONTAINER (window), vbox);
button = ctk_button_new_with_mnemonic ("_A button");
ctk_box_pack_start (CTK_BOX (vbox), button, FALSE, FALSE, 0);
button = ctk_button_new_with_mnemonic ("_B button");
ctk_box_pack_start (CTK_BOX (vbox), button, FALSE, FALSE, 0);
button = ctk_button_new_with_mnemonic ("_C button");
ctk_box_pack_start (CTK_BOX (vbox), button, FALSE, FALSE, 0);
button = ctk_button_new_with_mnemonic ("_D button");
ctk_box_pack_start (CTK_BOX (vbox), button, FALSE, FALSE, 0);
ctk_widget_show_all (window);
}
static void
toolbar_cb (GSimpleAction *action,
GVariant *parameter,
gpointer callback_data)
{
CtkWidget *window;
CtkWidget *vbox;
CtkWidget *label;
window = ctk_window_new (CTK_WINDOW_TOPLEVEL);
set_ctk_window_type (CTK_WINDOW (window), "_NET_WM_WINDOW_TYPE_TOOLBAR");
ctk_window_set_title (CTK_WINDOW (window), "Toolbar");
ctk_window_set_transient_for (CTK_WINDOW (window), CTK_WINDOW (callback_data));
vbox = ctk_box_new (CTK_ORIENTATION_VERTICAL, 0);
ctk_container_add (CTK_CONTAINER (window), vbox);
label = ctk_label_new ("FIXME this needs a resize grip, etc.");
ctk_box_pack_start (CTK_BOX (vbox), label, FALSE, FALSE, 0);
ctk_widget_show_all (window);
}
static void
menu_cb (GSimpleAction *action,
GVariant *parameter,
gpointer callback_data)
{
CtkWidget *window;
CtkWidget *vbox;
CtkWidget *label;
window = ctk_window_new (CTK_WINDOW_TOPLEVEL);
set_ctk_window_type (CTK_WINDOW (window), "_NET_WM_WINDOW_TYPE_MENU");
ctk_window_set_title (CTK_WINDOW (window), "Menu");
ctk_window_set_transient_for (CTK_WINDOW (window), CTK_WINDOW (callback_data));
vbox = ctk_box_new (CTK_ORIENTATION_VERTICAL, 0);
ctk_container_add (CTK_CONTAINER (window), vbox);
label = ctk_label_new ("FIXME this isn't a menu.");
ctk_box_pack_start (CTK_BOX (vbox), label, FALSE, FALSE, 0);
ctk_widget_show_all (window);
}
static void
override_redirect_cb (GSimpleAction *action,
GVariant *parameter,
gpointer callback_data)
{
CtkWidget *window;
CtkWidget *vbox;
CtkWidget *label;
window = ctk_window_new (CTK_WINDOW_POPUP);
ctk_window_set_title (CTK_WINDOW (window), "Override Redirect");
vbox = ctk_box_new (CTK_ORIENTATION_VERTICAL, 0);
ctk_container_add (CTK_CONTAINER (window), vbox);
label = ctk_label_new ("This is an override\nredirect window\nand should not be managed");
ctk_box_pack_start (CTK_BOX (vbox), label, FALSE, FALSE, 0);
ctk_widget_show_all (window);
}
static void
border_only_cb (GSimpleAction *action,
GVariant *parameter,
gpointer callback_data)
{
CtkWidget *window;
CtkWidget *vbox;
CtkWidget *label;
window = ctk_window_new (CTK_WINDOW_TOPLEVEL);
set_ctk_window_border_only (CTK_WINDOW (window));
ctk_window_set_title (CTK_WINDOW (window), "Border only");
ctk_window_set_transient_for (CTK_WINDOW (window), CTK_WINDOW (callback_data));
vbox = ctk_box_new (CTK_ORIENTATION_VERTICAL, 0);
ctk_container_add (CTK_CONTAINER (window), vbox);
label = ctk_label_new ("This window is supposed to have a border but no titlebar.");
ctk_box_pack_start (CTK_BOX (vbox), label, FALSE, FALSE, 0);
ctk_widget_show_all (window);
}
static gboolean
focus_in_event_cb (CtkWidget *window,
CdkEvent *event,
gpointer data)
{
CtkWidget *widget;
widget = CTK_WIDGET (data);
ctk_label_set_text (CTK_LABEL (widget), "Has focus");
return TRUE;
}
static gboolean
focus_out_event_cb (CtkWidget *window,
CdkEvent *event,
gpointer data)
{
CtkWidget *widget;
widget = CTK_WIDGET (data);
ctk_label_set_text (CTK_LABEL (widget), "Not focused");
return TRUE;
}
static CtkWidget*
focus_label (CtkWidget *window)
{
CtkWidget *label;
label = ctk_label_new ("Not focused");
g_signal_connect (G_OBJECT (window), "focus_in_event",
G_CALLBACK (focus_in_event_cb), label);
g_signal_connect (G_OBJECT (window), "focus_out_event",
G_CALLBACK (focus_out_event_cb), label);
return label;
}
static void
splashscreen_cb (GSimpleAction *action,
GVariant *parameter,
gpointer callback_data)
{
CtkWidget *window;
CtkWidget *image;
CtkWidget *vbox;
window = ctk_window_new (CTK_WINDOW_TOPLEVEL);
set_ctk_window_type (CTK_WINDOW (window), "_NET_WM_WINDOW_TYPE_SPLASH");
ctk_window_set_title (CTK_WINDOW (window), "Splashscreen");
vbox = ctk_box_new (CTK_ORIENTATION_VERTICAL, 0);
image = ctk_image_new_from_icon_name ("dialog-information", CTK_ICON_SIZE_DIALOG);
ctk_box_pack_start (CTK_BOX (vbox), image, FALSE, FALSE, 0);
ctk_box_pack_start (CTK_BOX (vbox), focus_label (window), FALSE, FALSE, 0);
ctk_container_add (CTK_CONTAINER (window), vbox);
ctk_widget_show_all (window);
}
enum
{
DOCK_TOP = 1,
DOCK_BOTTOM = 2,
DOCK_LEFT = 3,
DOCK_RIGHT = 4,
DOCK_ALL = 5
};
static void
make_dock (int type)
{
CtkWidget *window;
CtkWidget *image;
CtkWidget *box;
CtkWidget *button;
g_return_if_fail (type != DOCK_ALL);
box = NULL;
switch (type)
{
case DOCK_LEFT:
case DOCK_RIGHT:
box = ctk_box_new (CTK_ORIENTATION_VERTICAL, 0);
break;
case DOCK_TOP:
case DOCK_BOTTOM:
box = ctk_box_new (CTK_ORIENTATION_HORIZONTAL, 0);
break;
case DOCK_ALL:
break;
}
window = ctk_window_new (CTK_WINDOW_TOPLEVEL);
set_ctk_window_type (CTK_WINDOW (window), "_NET_WM_WINDOW_TYPE_DOCK");
image = ctk_image_new_from_icon_name ("dialog-information", CTK_ICON_SIZE_DIALOG);
ctk_box_pack_start (CTK_BOX (box), image, FALSE, FALSE, 0);
ctk_box_pack_start (CTK_BOX (box), focus_label (window), FALSE, FALSE, 0);
button = ctk_button_new_with_label ("Close");
ctk_box_pack_start (CTK_BOX (box), button, FALSE, FALSE, 0);
g_signal_connect_swapped (G_OBJECT (button), "clicked",
G_CALLBACK (ctk_widget_destroy), window);
ctk_container_add (CTK_CONTAINER (window), box);
#define DOCK_SIZE 48
switch (type)
{
case DOCK_LEFT:
ctk_widget_set_size_request (window, DOCK_SIZE, 400);
ctk_window_move (CTK_WINDOW (window), 0, 000);
set_ctk_window_struts (window, DOCK_SIZE, 0, 0, 0);
ctk_window_set_title (CTK_WINDOW (window), "LeftDock");
break;
case DOCK_RIGHT:
ctk_widget_set_size_request (window, DOCK_SIZE, 400);
ctk_window_move (CTK_WINDOW (window), WidthOfScreen (cdk_x11_screen_get_xscreen (cdk_screen_get_default ())) - DOCK_SIZE, 200);
set_ctk_window_struts (window, 0, DOCK_SIZE, 0, 0);
ctk_window_set_title (CTK_WINDOW (window), "RightDock");
break;
case DOCK_TOP:
ctk_widget_set_size_request (window, 600, DOCK_SIZE);
ctk_window_move (CTK_WINDOW (window), 76, 0);
set_ctk_window_struts (window, 0, 0, DOCK_SIZE, 0);
ctk_window_set_title (CTK_WINDOW (window), "TopDock");
break;
case DOCK_BOTTOM:
ctk_widget_set_size_request (window, 600, DOCK_SIZE);
ctk_window_move (CTK_WINDOW (window), 200, HeightOfScreen (cdk_x11_screen_get_xscreen (cdk_screen_get_default ())) - DOCK_SIZE);
set_ctk_window_struts (window, 0, 0, 0, DOCK_SIZE);
ctk_window_set_title (CTK_WINDOW (window), "BottomDock");
break;
case DOCK_ALL:
break;
}
ctk_widget_show_all (window);
}
static void
dock_cb (GSimpleAction *action,
GVariant *parameter,
gpointer callback_data)
{
guint callback_action;
const gchar *name;
g_object_get (G_OBJECT (action), "name", &name, NULL);
if (!g_strcmp0 (name, "top-dock"))
callback_action = DOCK_TOP;
else if (!g_strcmp0 (name, "bottom-dock"))
callback_action = DOCK_BOTTOM;
else if (!g_strcmp0 (name, "left-dock"))
callback_action = DOCK_LEFT;
else if (!g_strcmp0 (name, "right-dock"))
callback_action = DOCK_RIGHT;
else if (!g_strcmp0 (name, "all-docks"))
callback_action = DOCK_ALL;
else
return;
if (callback_action == DOCK_ALL)
{
make_dock (DOCK_TOP);
make_dock (DOCK_BOTTOM);
make_dock (DOCK_LEFT);
make_dock (DOCK_RIGHT);
}
else
{
make_dock (callback_action);
}
}
static void
override_background_color (CtkWidget *widget,
CdkRGBA *rgba)
{
gchar *css;
CtkCssProvider *provider;
provider = ctk_css_provider_new ();
css = g_strdup_printf ("* { background-color: %s; }",
cdk_rgba_to_string (rgba));
ctk_css_provider_load_from_data (provider, css, -1, NULL);
g_free (css);
ctk_style_context_add_provider (ctk_widget_get_style_context (widget),
CTK_STYLE_PROVIDER (provider),
CTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref (provider);
}
static void
desktop_cb (GSimpleAction *action,
GVariant *parameter,
gpointer callback_data)
{
CtkWidget *window;
CtkWidget *label;
CdkRGBA desktop_color;
window = ctk_window_new (CTK_WINDOW_TOPLEVEL);
set_ctk_window_type (CTK_WINDOW (window), "_NET_WM_WINDOW_TYPE_DESKTOP");
ctk_window_set_title (CTK_WINDOW (window), "Desktop");
ctk_widget_set_size_request (window,
WidthOfScreen (cdk_x11_screen_get_xscreen (cdk_screen_get_default ())),
HeightOfScreen (cdk_x11_screen_get_xscreen (cdk_screen_get_default ())));
ctk_window_move (CTK_WINDOW (window), 0, 0);
desktop_color.red = 0.32;
desktop_color.green = 0.46;
desktop_color.blue = 0.65;
desktop_color.alpha = 1.0;
override_background_color (window, &desktop_color);
label = focus_label (window);
ctk_container_add (CTK_CONTAINER (window), label);
ctk_widget_show_all (window);
}
static void
sleep_cb (GSimpleAction *action,<--- Parameter 'action' can be declared as pointer to const
GVariant *parameter,<--- Parameter 'parameter' can be declared as pointer to const
gpointer data)
{
sleep (1000);
}
static void
toggle_aspect_ratio (GSimpleAction *action,
GVariant *parameter,
gpointer data)
{
CtkWidget *window;
CdkGeometry geom;
CtkWidget *widget = CTK_WIDGET (data);
if (aspect_on)
{
geom.min_aspect = 0;
geom.max_aspect = 65535;
}
else
{
geom.min_aspect = 1.777778;
geom.max_aspect = 1.777778;
}
aspect_on = !aspect_on;
window = ctk_widget_get_ancestor (widget, CTK_TYPE_WINDOW);
if (window)
ctk_window_set_geometry_hints (CTK_WINDOW (window),
CTK_WIDGET (data),
&geom,
CDK_HINT_ASPECT);
}
static void
toggle_decorated_cb (GSimpleAction *action,
GVariant *parameter,
gpointer data)
{
CtkWidget *window;
window = ctk_widget_get_ancestor (data, CTK_TYPE_WINDOW);
if (window)
ctk_window_set_decorated (CTK_WINDOW (window),
!ctk_window_get_decorated (CTK_WINDOW (window)));
}
static void
clicked_toolbar_cb (GSimpleAction *action,
GVariant *parameter,
gpointer data)
{
CtkWidget *dialog;
dialog = ctk_message_dialog_new (CTK_WINDOW (data),
CTK_DIALOG_DESTROY_WITH_PARENT,
CTK_MESSAGE_INFO,
CTK_BUTTONS_CLOSE,
"Clicking the toolbar buttons doesn't do anything");
/* Close dialog on user response */
g_signal_connect (G_OBJECT (dialog),
"response",
G_CALLBACK (ctk_widget_destroy),
NULL);
ctk_widget_show (dialog);
}
static void
update_statusbar (CtkTextBuffer *buffer,
CtkStatusbar *statusbar)
{
gchar *msg;
gint row, col;
gint count;
CtkTextIter iter;
ctk_statusbar_pop (statusbar, 0); /* clear any previous message, underflow is allowed */
count = ctk_text_buffer_get_char_count (buffer);
ctk_text_buffer_get_iter_at_mark (buffer,
&iter,
ctk_text_buffer_get_insert (buffer));
row = ctk_text_iter_get_line (&iter);
col = ctk_text_iter_get_line_offset (&iter);
msg = g_strdup_printf ("Cursor at row %d column %d - %d chars in document",
row, col, count);
ctk_statusbar_push (statusbar, 0, msg);
g_free (msg);
}
static void
mark_set_callback (CtkTextBuffer *buffer,
const CtkTextIter *new_location,
CtkTextMark *mark,
gpointer data)
{
update_statusbar (buffer, CTK_STATUSBAR (data));
}
static int window_count = 0;
static void
destroy_cb (CtkWidget *w, gpointer data)<--- Parameter 'w' can be declared as pointer to const
{
--window_count;
if (window_count == 0)
ctk_main_quit ();
}
static const gchar *xml =
"<interface>"
"<menu id='menubar'>"
"<submenu>"
"<attribute name='label'>Windows</attribute>"
"<section>"
"<item>"
"<attribute name='label'>Dialog</attribute>"
"<attribute name='action'>demo.dialog1</attribute>"
"<attribute name='accel'><control>d</attribute>"
"</item>"
"<item>"
"<attribute name='label'>Modal dialog</attribute>"
"<attribute name='action'>demo.dialog2</attribute>"
"</item>"
"<item>"
"<attribute name='label'>Parentless dialog</attribute>"
"<attribute name='action'>demo.dialog3</attribute>"
"</item>"
"<item>"
"<attribute name='label'>Utility</attribute>"
"<attribute name='action'>demo.utility</attribute>"
"<attribute name='accel'><control>u</attribute>"
"</item>"
"<item>"
"<attribute name='label'>Splashscreen</attribute>"
"<attribute name='action'>demo.splashscreen</attribute>"
"<attribute name='accel'><control>s</attribute>"
"</item>"
"<item>"
"<attribute name='label'>Top dock</attribute>"
"<attribute name='action'>demo.top-dock</attribute>"
"</item>"
"<item>"
"<attribute name='label'>Bottom dock</attribute>"
"<attribute name='action'>demo.bottom-dock</attribute>"
"</item>"
"<item>"
"<attribute name='label'>Left dock</attribute>"
"<attribute name='action'>demo.left-dock</attribute>"
"</item>"
"<item>"
"<attribute name='label'>Right dock</attribute>"
"<attribute name='action'>demo.right-dock</attribute>"
"</item>"
"<item>"
"<attribute name='label'>All docks</attribute>"
"<attribute name='action'>demo.all-docks</attribute>"
"</item>"
"<item>"
"<attribute name='label'>Desktop</attribute>"
"<attribute name='action'>demo.desktop</attribute>"
"</item>"
"<item>"
"<attribute name='label'>Menu</attribute>"
"<attribute name='action'>demo.menu</attribute>"
"</item>"
"<item>"
"<attribute name='label'>Toolbar</attribute>"
"<attribute name='action'>demo.toolbar</attribute>"
"</item>"
"<item>"
"<attribute name='label'>Override Redirect</attribute>"
"<attribute name='action'>demo.override-redirect</attribute>"
"</item>"
"<item>"
"<attribute name='label'>Border Only</attribute>"
"<attribute name='action'>demo.border-only</attribute>"
"</item>"
"</section>"
"</submenu>"
"</menu>"
"</interface>";
static GActionEntry demo_entries[] =
{
/* menubar */
{ "dialog1", dialog_cb, NULL, NULL, NULL, {} },
{ "dialog2", modal_dialog_cb, NULL, NULL, NULL, {} },
{ "dialog3", no_parent_dialog_cb, NULL, NULL, NULL, {} },
{ "utility", utility_cb, NULL, NULL, NULL, {} },
{ "splashscreen", splashscreen_cb, NULL, NULL, NULL, {} },
{ "top-dock", dock_cb, NULL, NULL, NULL, {} },
{ "bottom-dock", dock_cb, NULL, NULL, NULL, {} },
{ "left-dock", dock_cb, NULL, NULL, NULL, {} },
{ "right-dock", dock_cb, NULL, NULL, NULL, {} },
{ "all-docks", dock_cb, NULL, NULL, NULL, {} },
{ "desktop", desktop_cb, NULL, NULL, NULL, {} },
{ "menu", menu_cb, NULL, NULL, NULL, {} },
{ "toolbar", toolbar_cb, NULL, NULL, NULL, {} },
{ "override-redirect", override_redirect_cb, NULL, NULL, NULL, {} },
{ "border-only", border_only_cb, NULL, NULL, NULL, {} },
/* toolbar */
{ "new", do_appwindow, NULL, NULL, NULL, {} },
{ "lock", sleep_cb, NULL, NULL, NULL, {} },<--- You might need to cast the function pointer here<--- You might need to cast the function pointer here
{ "decorations", toggle_decorated_cb, NULL, NULL, NULL, {} },
{ "quit", clicked_toolbar_cb, NULL, NULL, NULL, {} },
{ "ratio", toggle_aspect_ratio, NULL, NULL, NULL, {} },
};
static CtkWidget *
create_toolbar (void)
{
CtkWidget *toolbar;
CtkToolItem *item;
toolbar = ctk_toolbar_new ();
item = ctk_tool_button_new (ctk_image_new_from_icon_name ("document-new", CTK_ICON_SIZE_SMALL_TOOLBAR), NULL);
ctk_tool_item_set_tooltip_markup (item, "Open another one of these windows");
ctk_actionable_set_action_name (CTK_ACTIONABLE (item), "demo.new");
ctk_toolbar_insert (CTK_TOOLBAR (toolbar), item, -1);
item = ctk_tool_button_new (ctk_image_new_from_icon_name ("document-open", CTK_ICON_SIZE_SMALL_TOOLBAR), NULL);
ctk_tool_item_set_tooltip_markup (item, "This is a demo button that locks up the demo");
ctk_actionable_set_action_name (CTK_ACTIONABLE (item), "demo.lock");
ctk_toolbar_insert (CTK_TOOLBAR (toolbar), item, -1);
item = ctk_tool_button_new (ctk_image_new_from_icon_name ("document-open", CTK_ICON_SIZE_SMALL_TOOLBAR), NULL);
ctk_tool_item_set_tooltip_markup (item, "This is a demo button that toggles window decorations");
ctk_actionable_set_action_name (CTK_ACTIONABLE (item), "demo.decorations");
ctk_toolbar_insert (CTK_TOOLBAR (toolbar), item, -1);
item = ctk_tool_button_new (ctk_image_new_from_icon_name ("document-open", CTK_ICON_SIZE_SMALL_TOOLBAR), NULL);
ctk_tool_item_set_tooltip_markup (item, "This is a demo button that locks the aspect ratio using a hint");
ctk_actionable_set_action_name (CTK_ACTIONABLE (item), "demo.ratio");
ctk_toolbar_insert (CTK_TOOLBAR (toolbar), item, -1);
item = ctk_tool_button_new (ctk_image_new_from_icon_name ("ctk-quit", CTK_ICON_SIZE_SMALL_TOOLBAR), NULL);
ctk_tool_item_set_tooltip_markup (item, "This is a demo button with a 'quit' icon");
ctk_actionable_set_action_name (CTK_ACTIONABLE (item), "demo.quit");
ctk_toolbar_insert (CTK_TOOLBAR (toolbar), item, -1);
return toolbar;
}
static void
do_appwindow (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
CtkWidget *window;
CtkWidget *grid;
CtkWidget *toolbar;
GSimpleActionGroup *action_group;
CtkBuilder *builder;
CtkWidget *statusbar;
CtkWidget *contents;
CtkWidget *sw;
CtkTextBuffer *buffer;
/* Create the toplevel window
*/
++window_count;
aspect_on = FALSE;
window = ctk_window_new (CTK_WINDOW_TOPLEVEL);
ctk_window_set_title (CTK_WINDOW (window), "Application Window");
g_signal_connect (G_OBJECT (window), "destroy",
G_CALLBACK (destroy_cb), NULL);<--- You might need to cast the function pointer here
grid = ctk_grid_new ();
ctk_widget_set_vexpand (grid, TRUE);
ctk_widget_set_hexpand (grid, TRUE);
ctk_container_add (CTK_CONTAINER (window), grid);
action_group = g_simple_action_group_new ();
builder = ctk_builder_new_from_string (xml, -1);
g_action_map_add_action_entries (G_ACTION_MAP (action_group),
demo_entries,
G_N_ELEMENTS (demo_entries),
window);
ctk_widget_insert_action_group (window, "demo", G_ACTION_GROUP (action_group));
/* Create the menubar
*/
GMenuModel *model = G_MENU_MODEL (ctk_builder_get_object (builder, "menubar"));
CtkWidget *menubar = ctk_menu_bar_new_from_model (model);
ctk_grid_attach (CTK_GRID (grid), menubar, 0, 0, 1, 1);
ctk_widget_set_hexpand (menubar, TRUE);
/* Create the toolbar
*/
toolbar = create_toolbar ();
ctk_grid_attach (CTK_GRID (grid), toolbar, 0, 1, 1, 1);
ctk_widget_set_hexpand (toolbar, TRUE);
/* Create document
*/
sw = ctk_scrolled_window_new (NULL, NULL);
ctk_scrolled_window_set_policy (CTK_SCROLLED_WINDOW (sw),
CTK_POLICY_AUTOMATIC,
CTK_POLICY_AUTOMATIC);
ctk_scrolled_window_set_shadow_type (CTK_SCROLLED_WINDOW (sw),
CTK_SHADOW_IN);
ctk_grid_attach (CTK_GRID (grid), sw, 0, 2, 1, 1);
ctk_widget_set_hexpand (sw, TRUE);
ctk_widget_set_vexpand (sw, TRUE);
ctk_window_set_default_size (CTK_WINDOW (window),
200, 200);
contents = ctk_text_view_new ();
ctk_text_view_set_wrap_mode (CTK_TEXT_VIEW (contents),
PANGO_WRAP_WORD);
ctk_container_add (CTK_CONTAINER (sw),
contents);
/* Create statusbar */
statusbar = ctk_statusbar_new ();
ctk_grid_attach (CTK_GRID (grid), statusbar, 0, 3, 1, 1);
ctk_widget_set_hexpand (statusbar, TRUE);
/* Show text widget info in the statusbar */
buffer = ctk_text_view_get_buffer (CTK_TEXT_VIEW (contents));
ctk_text_buffer_set_text (buffer,
"This demo demonstrates various kinds of windows that "
"window managers and window manager themes should handle. "
"Be sure to tear off the menu and toolbar, those are also "
"a special kind of window.",
-1);
g_signal_connect_object (buffer,
"changed",
G_CALLBACK (update_statusbar),
statusbar,
0);
g_signal_connect_object (buffer,
"mark_set", /* cursor moved */
G_CALLBACK (mark_set_callback),
statusbar,
0);
update_statusbar (buffer, CTK_STATUSBAR (statusbar));
ctk_widget_show_all (window);
g_object_unref (action_group);
g_object_unref (builder);
}
|