Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ pub fn build(b: *std.Build) !void {
scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml");
scanner.generate("xdg_wm_base", 1);

scanner.addSystemProtocol("unstable/xdg-decoration/xdg-decoration-unstable-v1.xml");
scanner.generate("zxdg_decoration_manager_v1", 1);

exe.root_module.addImport("wayland", wayland);
exe.linkLibC();
exe.linkSystemLibrary("wayland-client");
Expand Down
18 changes: 18 additions & 0 deletions src/wayland.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const Config = configpkg.Config;
const wayland = @import("wayland");
const wl = wayland.client.wl;
const xdg = wayland.client.xdg;
const zxdg = wayland.client.zxdg;
const zwp = wayland.client.zwp;
const wp = wayland.client.wp;

Expand All @@ -42,6 +43,7 @@ const Context = struct {
compositor: ?*wl.Compositor,
wm_base: ?*xdg.WmBase,
data_device_manager: ?*wl.DataDeviceManager,
decoration_manager: ?*zxdg.DecorationManagerV1,
selection_device_manager: ?*zwp.PrimarySelectionDeviceManagerV1,
cursor_shape_manager: ?*wp.CursorShapeManagerV1,
surface_map: *SurfaceMap,
Expand Down Expand Up @@ -684,6 +686,8 @@ fn registryListener(registry: *wl.Registry, event: wl.Registry.Event, context: *
context.selection_device_manager = registry.bind(global.name, zwp.PrimarySelectionDeviceManagerV1, 1) catch return;
} else if (std.mem.orderZ(u8, global.interface, wp.CursorShapeManagerV1.interface.name) == .eq) {
context.cursor_shape_manager = registry.bind(global.name, wp.CursorShapeManagerV1, 1) catch return;
} else if (std.mem.orderZ(u8, global.interface, zxdg.DecorationManagerV1.interface.name) == .eq) {
context.decoration_manager = registry.bind(global.name, zxdg.DecorationManagerV1, 1) catch return;
}
},
.global_remove => {},
Expand All @@ -697,6 +701,7 @@ pub const App = struct {
wm_base: *xdg.WmBase,
registry: *wl.Registry,
data_device_manager: *wl.DataDeviceManager,
decoration_manager: ?*zxdg.DecorationManagerV1,
selection_device_manager: *zwp.PrimarySelectionDeviceManagerV1,
data_device: *wl.DataDevice,
selection_device: *zwp.PrimarySelectionDeviceV1,
Expand Down Expand Up @@ -733,6 +738,7 @@ pub const App = struct {
.compositor = null,
.wm_base = null,
.data_device_manager = null,
.decoration_manager = null,
.selection_device_manager = null,
.cursor_shape_manager = null,
.surface_map = surface_map,
Expand Down Expand Up @@ -839,6 +845,7 @@ pub const App = struct {
.wm_base = wm_base,
.data_device_manager = data_device_manager,
.data_device = data_device,
.decoration_manager = context.decoration_manager,
.selection_device_manager = selection_device_manager,
.selection_device = selection_device,
.cursor_shape_manager = cursor_shape_manager,
Expand Down Expand Up @@ -1278,6 +1285,7 @@ pub const Surface = struct {
wl_surface: *wl.Surface,
xdg_surface: *xdg.Surface,
xdg_toplevel: *xdg.Toplevel,
xdg_decoration: ?*zxdg.ToplevelDecorationV1,

data_offer: ?*wl.DataOffer,
selection_offer: ?*zwp.PrimarySelectionOfferV1,
Expand Down Expand Up @@ -1338,6 +1346,7 @@ pub const Surface = struct {
self.pressed_key = null;
self.repeat_rate = 0;
self.repeat_delay = 0;
self.xdg_decoration = null;

self.wl_surface = try app.compositor.createSurface();
errdefer self.wl_surface.destroy();
Expand All @@ -1348,6 +1357,11 @@ pub const Surface = struct {
self.xdg_surface.setListener(*Surface, xdgSurfaceListener, self);
self.xdg_toplevel.setListener(*Surface, xdgToplevelListener, self);

if (app.decoration_manager) |decoration_manager| {
self.xdg_decoration = try decoration_manager.getToplevelDecoration(self.xdg_toplevel);
self.xdg_decoration.?.setMode(.server_side);
}

const app_id = app.config.class orelse "com.mitchellh.ghostty";
self.xdg_toplevel.setAppId(app_id);

Expand Down Expand Up @@ -1416,6 +1430,10 @@ pub const Surface = struct {
// Clean up our core surface so that all the rendering and IO stop.
self.core_surface.deinit();

if (self.xdg_decoration) |decor| {
decor.destroy();
}

self.xdg_toplevel.destroy();
self.xdg_surface.destroy();
self.wl_surface.destroy();
Expand Down