@@ -7,9 +7,15 @@ const Window = @This();
7
7
8
8
const std = @import ("std" );
9
9
const builtin = @import ("builtin" );
10
- const build_config = @import ("../../build_config.zig" );
11
10
const Allocator = std .mem .Allocator ;
12
11
const assert = std .debug .assert ;
12
+
13
+ const gio = @import ("gio" );
14
+ const glib = @import ("glib" );
15
+ const gobject = @import ("gobject" );
16
+ const gtk = @import ("gtk" );
17
+
18
+ const build_config = @import ("../../build_config.zig" );
13
19
const configpkg = @import ("../../config.zig" );
14
20
const font = @import ("../../font/main.zig" );
15
21
const input = @import ("../../input.zig" );
@@ -475,36 +481,38 @@ fn toggleCssClass(
475
481
/// menus and such. The menu is defined in App.zig but the action is defined
476
482
/// here. The string name binds them.
477
483
fn initActions (self : * Window ) void {
484
+ // FIXME: when rest of file is converted to gobject
485
+ const window : * gtk.ApplicationWindow = @ptrCast (@alignCast (self .window ));
486
+ const action_map = window .as (gio .ActionMap );
478
487
const actions = .{
479
- .{ "about" , & gtkActionAbout },
480
- .{ "close" , & gtkActionClose },
481
- .{ "new-window" , & gtkActionNewWindow },
482
- .{ "new-tab" , & gtkActionNewTab },
483
- .{ "close-tab" , & gtkActionCloseTab },
484
- .{ "split-right" , & gtkActionSplitRight },
485
- .{ "split-down" , & gtkActionSplitDown },
486
- .{ "split-left" , & gtkActionSplitLeft },
487
- .{ "split-up" , & gtkActionSplitUp },
488
- .{ "toggle-inspector" , & gtkActionToggleInspector },
489
- .{ "copy" , & gtkActionCopy },
490
- .{ "paste" , & gtkActionPaste },
491
- .{ "reset" , & gtkActionReset },
492
- .{ "clear" , & gtkActionClear },
493
- .{ "prompt-title" , & gtkActionPromptTitle },
488
+ .{ "about" , gtkActionAbout },
489
+ .{ "close" , gtkActionClose },
490
+ .{ "new-window" , gtkActionNewWindow },
491
+ .{ "new-tab" , gtkActionNewTab },
492
+ .{ "close-tab" , gtkActionCloseTab },
493
+ .{ "split-right" , gtkActionSplitRight },
494
+ .{ "split-down" , gtkActionSplitDown },
495
+ .{ "split-left" , gtkActionSplitLeft },
496
+ .{ "split-up" , gtkActionSplitUp },
497
+ .{ "toggle-inspector" , gtkActionToggleInspector },
498
+ .{ "copy" , gtkActionCopy },
499
+ .{ "paste" , gtkActionPaste },
500
+ .{ "reset" , gtkActionReset },
501
+ .{ "clear" , gtkActionClear },
502
+ .{ "prompt-title" , gtkActionPromptTitle },
494
503
};
495
504
496
505
inline for (actions ) | entry | {
497
- const action = c . g_simple_action_new (entry [0 ], null );
498
- defer c . g_object_unref ( action );
499
- _ = c . g_signal_connect_data (
506
+ const action = gio . SimpleAction . new (entry [0 ], null );
507
+ defer action . unref ( );
508
+ _ = gio . SimpleAction . signals . activate . connect (
500
509
action ,
501
- "activate" ,
502
- c . G_CALLBACK ( entry [1 ]) ,
510
+ * Window ,
511
+ entry [1 ],
503
512
self ,
504
- null ,
505
- c .G_CONNECT_DEFAULT ,
513
+ .{},
506
514
);
507
- c . g_action_map_add_action ( @ptrCast ( self . window ), @ptrCast ( action ));
515
+ action_map . addAction ( action . as ( gio . Action ));
508
516
}
509
517
}
510
518
@@ -878,12 +886,10 @@ fn gtkKeyPressed(
878
886
}
879
887
880
888
fn gtkActionAbout (
881
- _ : * c.GSimpleAction ,
882
- _ : * c.GVariant ,
883
- ud : ? * anyopaque ,
889
+ _ : * gio.SimpleAction ,
890
+ _ : ? * glib.Variant ,
891
+ self : * Window ,
884
892
) callconv (.C ) void {
885
- const self : * Window = @ptrCast (@alignCast (ud orelse return ));
886
-
887
893
const name = "Ghostty" ;
888
894
const icon = "com.mitchellh.ghostty" ;
889
895
const website = "https://ghostty.org" ;
@@ -924,20 +930,18 @@ fn gtkActionAbout(
924
930
}
925
931
926
932
fn gtkActionClose (
927
- _ : * c.GSimpleAction ,
928
- _ : * c.GVariant ,
929
- ud : ? * anyopaque ,
933
+ _ : * gio.SimpleAction ,
934
+ _ : ? * glib.Variant ,
935
+ self : * Window ,
930
936
) callconv (.C ) void {
931
- const self : * Window = @ptrCast (@alignCast (ud orelse return ));
932
937
c .gtk_window_destroy (self .window );
933
938
}
934
939
935
940
fn gtkActionNewWindow (
936
- _ : * c.GSimpleAction ,
937
- _ : * c.GVariant ,
938
- ud : ? * anyopaque ,
941
+ _ : * gio.SimpleAction ,
942
+ _ : ? * glib.Variant ,
943
+ self : * Window ,
939
944
) callconv (.C ) void {
940
- const self : * Window = @ptrCast (@alignCast (ud orelse return ));
941
945
const surface = self .actionSurface () orelse return ;
942
946
_ = surface .performBindingAction (.{ .new_window = {} }) catch | err | {
943
947
log .warn ("error performing binding action error={}" , .{err });
@@ -946,20 +950,19 @@ fn gtkActionNewWindow(
946
950
}
947
951
948
952
fn gtkActionNewTab (
949
- _ : * c.GSimpleAction ,
950
- _ : * c.GVariant ,
951
- ud : ? * anyopaque ,
953
+ _ : * gio.SimpleAction ,
954
+ _ : ? * glib.Variant ,
955
+ self : * Window ,
952
956
) callconv (.C ) void {
953
957
// We can use undefined because the button is not used.
954
- gtkTabNewClick (undefined , ud );
958
+ gtkTabNewClick (undefined , self );
955
959
}
956
960
957
961
fn gtkActionCloseTab (
958
- _ : * c.GSimpleAction ,
959
- _ : * c.GVariant ,
960
- ud : ? * anyopaque ,
962
+ _ : * gio.SimpleAction ,
963
+ _ : ? * glib.Variant ,
964
+ self : * Window ,
961
965
) callconv (.C ) void {
962
- const self : * Window = @ptrCast (@alignCast (ud orelse return ));
963
966
const surface = self .actionSurface () orelse return ;
964
967
_ = surface .performBindingAction (.{ .close_tab = {} }) catch | err | {
965
968
log .warn ("error performing binding action error={}" , .{err });
@@ -968,11 +971,10 @@ fn gtkActionCloseTab(
968
971
}
969
972
970
973
fn gtkActionSplitRight (
971
- _ : * c.GSimpleAction ,
972
- _ : * c.GVariant ,
973
- ud : ? * anyopaque ,
974
+ _ : * gio.SimpleAction ,
975
+ _ : ? * glib.Variant ,
976
+ self : * Window ,
974
977
) callconv (.C ) void {
975
- const self : * Window = @ptrCast (@alignCast (ud orelse return ));
976
978
const surface = self .actionSurface () orelse return ;
977
979
_ = surface .performBindingAction (.{ .new_split = .right }) catch | err | {
978
980
log .warn ("error performing binding action error={}" , .{err });
@@ -981,11 +983,10 @@ fn gtkActionSplitRight(
981
983
}
982
984
983
985
fn gtkActionSplitDown (
984
- _ : * c.GSimpleAction ,
985
- _ : * c.GVariant ,
986
- ud : ? * anyopaque ,
986
+ _ : * gio.SimpleAction ,
987
+ _ : ? * glib.Variant ,
988
+ self : * Window ,
987
989
) callconv (.C ) void {
988
- const self : * Window = @ptrCast (@alignCast (ud orelse return ));
989
990
const surface = self .actionSurface () orelse return ;
990
991
_ = surface .performBindingAction (.{ .new_split = .down }) catch | err | {
991
992
log .warn ("error performing binding action error={}" , .{err });
@@ -994,11 +995,10 @@ fn gtkActionSplitDown(
994
995
}
995
996
996
997
fn gtkActionSplitLeft (
997
- _ : * c.GSimpleAction ,
998
- _ : * c.GVariant ,
999
- ud : ? * anyopaque ,
998
+ _ : * gio.SimpleAction ,
999
+ _ : ? * glib.Variant ,
1000
+ self : * Window ,
1000
1001
) callconv (.C ) void {
1001
- const self : * Window = @ptrCast (@alignCast (ud orelse return ));
1002
1002
const surface = self .actionSurface () orelse return ;
1003
1003
_ = surface .performBindingAction (.{ .new_split = .left }) catch | err | {
1004
1004
log .warn ("error performing binding action error={}" , .{err });
@@ -1007,11 +1007,10 @@ fn gtkActionSplitLeft(
1007
1007
}
1008
1008
1009
1009
fn gtkActionSplitUp (
1010
- _ : * c.GSimpleAction ,
1011
- _ : * c.GVariant ,
1012
- ud : ? * anyopaque ,
1010
+ _ : * gio.SimpleAction ,
1011
+ _ : ? * glib.Variant ,
1012
+ self : * Window ,
1013
1013
) callconv (.C ) void {
1014
- const self : * Window = @ptrCast (@alignCast (ud orelse return ));
1015
1014
const surface = self .actionSurface () orelse return ;
1016
1015
_ = surface .performBindingAction (.{ .new_split = .up }) catch | err | {
1017
1016
log .warn ("error performing binding action error={}" , .{err });
@@ -1020,11 +1019,10 @@ fn gtkActionSplitUp(
1020
1019
}
1021
1020
1022
1021
fn gtkActionToggleInspector (
1023
- _ : * c.GSimpleAction ,
1024
- _ : * c.GVariant ,
1025
- ud : ? * anyopaque ,
1022
+ _ : * gio.SimpleAction ,
1023
+ _ : ? * glib.Variant ,
1024
+ self : * Window ,
1026
1025
) callconv (.C ) void {
1027
- const self : * Window = @ptrCast (@alignCast (ud orelse return ));
1028
1026
const surface = self .actionSurface () orelse return ;
1029
1027
_ = surface .performBindingAction (.{ .inspector = .toggle }) catch | err | {
1030
1028
log .warn ("error performing binding action error={}" , .{err });
@@ -1033,11 +1031,10 @@ fn gtkActionToggleInspector(
1033
1031
}
1034
1032
1035
1033
fn gtkActionCopy (
1036
- _ : * c.GSimpleAction ,
1037
- _ : * c.GVariant ,
1038
- ud : ? * anyopaque ,
1034
+ _ : * gio.SimpleAction ,
1035
+ _ : ? * glib.Variant ,
1036
+ self : * Window ,
1039
1037
) callconv (.C ) void {
1040
- const self : * Window = @ptrCast (@alignCast (ud orelse return ));
1041
1038
const surface = self .actionSurface () orelse return ;
1042
1039
_ = surface .performBindingAction (.{ .copy_to_clipboard = {} }) catch | err | {
1043
1040
log .warn ("error performing binding action error={}" , .{err });
@@ -1046,11 +1043,10 @@ fn gtkActionCopy(
1046
1043
}
1047
1044
1048
1045
fn gtkActionPaste (
1049
- _ : * c.GSimpleAction ,
1050
- _ : * c.GVariant ,
1051
- ud : ? * anyopaque ,
1046
+ _ : * gio.SimpleAction ,
1047
+ _ : ? * glib.Variant ,
1048
+ self : * Window ,
1052
1049
) callconv (.C ) void {
1053
- const self : * Window = @ptrCast (@alignCast (ud orelse return ));
1054
1050
const surface = self .actionSurface () orelse return ;
1055
1051
_ = surface .performBindingAction (.{ .paste_from_clipboard = {} }) catch | err | {
1056
1052
log .warn ("error performing binding action error={}" , .{err });
@@ -1059,11 +1055,10 @@ fn gtkActionPaste(
1059
1055
}
1060
1056
1061
1057
fn gtkActionReset (
1062
- _ : * c.GSimpleAction ,
1063
- _ : * c.GVariant ,
1064
- ud : ? * anyopaque ,
1058
+ _ : * gio.SimpleAction ,
1059
+ _ : ? * glib.Variant ,
1060
+ self : * Window ,
1065
1061
) callconv (.C ) void {
1066
- const self : * Window = @ptrCast (@alignCast (ud orelse return ));
1067
1062
const surface = self .actionSurface () orelse return ;
1068
1063
_ = surface .performBindingAction (.{ .reset = {} }) catch | err | {
1069
1064
log .warn ("error performing binding action error={}" , .{err });
@@ -1072,11 +1067,10 @@ fn gtkActionReset(
1072
1067
}
1073
1068
1074
1069
fn gtkActionClear (
1075
- _ : * c.GSimpleAction ,
1076
- _ : * c.GVariant ,
1077
- ud : ? * anyopaque ,
1070
+ _ : * gio.SimpleAction ,
1071
+ _ : ? * glib.Variant ,
1072
+ self : * Window ,
1078
1073
) callconv (.C ) void {
1079
- const self : * Window = @ptrCast (@alignCast (ud orelse return ));
1080
1074
const surface = self .actionSurface () orelse return ;
1081
1075
_ = surface .performBindingAction (.{ .clear_screen = {} }) catch | err | {
1082
1076
log .warn ("error performing binding action error={}" , .{err });
@@ -1085,11 +1079,10 @@ fn gtkActionClear(
1085
1079
}
1086
1080
1087
1081
fn gtkActionPromptTitle (
1088
- _ : * c.GSimpleAction ,
1089
- _ : * c.GVariant ,
1090
- ud : ? * anyopaque ,
1082
+ _ : * gio.SimpleAction ,
1083
+ _ : ? * glib.Variant ,
1084
+ self : * Window ,
1091
1085
) callconv (.C ) void {
1092
- const self : * Window = @ptrCast (@alignCast (ud orelse return ));
1093
1086
const surface = self .actionSurface () orelse return ;
1094
1087
_ = surface .performBindingAction (.{ .prompt_surface_title = {} }) catch | err | {
1095
1088
log .warn ("error performing binding action error={}" , .{err });
0 commit comments