core: implement Linux.setTitle()
This commit is contained in:
parent
ae1d49b51a
commit
15c63e8334
3 changed files with 27 additions and 13 deletions
|
|
@ -49,8 +49,8 @@ backend: Backend,
|
||||||
|
|
||||||
// these arrays are used as info messages to the user that some features are missing
|
// these arrays are used as info messages to the user that some features are missing
|
||||||
// please keep these up to date until we can remove them
|
// please keep these up to date until we can remove them
|
||||||
const MISSING_FEATURES_X11 = [_][]const u8{ "Resizing window", "Changing display mode", "VSync", "Setting window border/title/cursor" };
|
const MISSING_FEATURES_X11 = [_][]const u8{ "Resizing window", "Changing display mode", "VSync", "Setting window border/cursor" };
|
||||||
const MISSING_FEATURES_WAYLAND = [_][]const u8{ "Changing display mode", "VSync", "Setting window border/title/cursor" };
|
const MISSING_FEATURES_WAYLAND = [_][]const u8{ "Changing display mode", "VSync", "Setting window border/cursor" };
|
||||||
|
|
||||||
pub fn init(
|
pub fn init(
|
||||||
linux: *Linux,
|
linux: *Linux,
|
||||||
|
|
@ -128,8 +128,6 @@ pub fn init(
|
||||||
// warn about incomplete features
|
// warn about incomplete features
|
||||||
// TODO: remove this when linux is not missing major features
|
// TODO: remove this when linux is not missing major features
|
||||||
try warnAboutIncompleteFeatures(linux.backend, &MISSING_FEATURES_X11, &MISSING_FEATURES_WAYLAND, options.allocator);
|
try warnAboutIncompleteFeatures(linux.backend, &MISSING_FEATURES_X11, &MISSING_FEATURES_WAYLAND, options.allocator);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(linux: *Linux) void {
|
pub fn deinit(linux: *Linux) void {
|
||||||
|
|
@ -141,8 +139,6 @@ pub fn deinit(linux: *Linux) void {
|
||||||
.wayland => linux.backend.wayland.deinit(linux),
|
.wayland => linux.backend.wayland.deinit(linux),
|
||||||
.x11 => linux.backend.x11.deinit(linux),
|
.x11 => linux.backend.x11.deinit(linux),
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(linux: *Linux) !void {
|
pub fn update(linux: *Linux) !void {
|
||||||
|
|
@ -150,11 +146,19 @@ pub fn update(linux: *Linux) !void {
|
||||||
.wayland => try linux.backend.wayland.update(linux),
|
.wayland => try linux.backend.wayland.update(linux),
|
||||||
.x11 => try linux.backend.x11.update(linux),
|
.x11 => try linux.backend.x11.update(linux),
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setTitle(_: *Linux, _: [:0]const u8) void {
|
pub fn setTitle(linux: *Linux, title: [:0]const u8) void {
|
||||||
|
const new_title = linux.allocator.dupeZ(u8, title) catch {
|
||||||
|
log.err("Failed to reallocate memory for new window title", .{});
|
||||||
return;
|
return;
|
||||||
|
};
|
||||||
|
linux.allocator.free(linux.title);
|
||||||
|
linux.title = new_title;
|
||||||
|
switch (linux.backend) {
|
||||||
|
.wayland => linux.backend.wayland.setTitle(linux.title),
|
||||||
|
.x11 => linux.backend.x11.setTitle(linux.title),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setDisplayMode(_: *Linux, _: DisplayMode) void {
|
pub fn setDisplayMode(_: *Linux, _: DisplayMode) void {
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ configured: bool = false,
|
||||||
|
|
||||||
display: *c.wl_display,
|
display: *c.wl_display,
|
||||||
surface: *c.wl_surface,
|
surface: *c.wl_surface,
|
||||||
|
toplevel: *c.xdg_toplevel,
|
||||||
interfaces: Interfaces,
|
interfaces: Interfaces,
|
||||||
libwaylandclient: LibWaylandClient,
|
libwaylandclient: LibWaylandClient,
|
||||||
|
|
||||||
|
|
@ -99,6 +100,7 @@ pub fn init(
|
||||||
},
|
},
|
||||||
.surface_descriptor = undefined,
|
.surface_descriptor = undefined,
|
||||||
.surface = undefined,
|
.surface = undefined,
|
||||||
|
.toplevel = undefined,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
var wl = &linux.backend.wayland;
|
var wl = &linux.backend.wayland;
|
||||||
|
|
@ -138,13 +140,13 @@ pub fn init(
|
||||||
}
|
}
|
||||||
|
|
||||||
const xdg_surface = c.xdg_wm_base_get_xdg_surface(wl.interfaces.xdg_wm_base, wl.surface) orelse return error.UnableToCreateXdgSurface;
|
const xdg_surface = c.xdg_wm_base_get_xdg_surface(wl.interfaces.xdg_wm_base, wl.surface) orelse return error.UnableToCreateXdgSurface;
|
||||||
const toplevel = c.xdg_surface_get_toplevel(xdg_surface) orelse return error.UnableToGetXdgTopLevel;
|
wl.toplevel = c.xdg_surface_get_toplevel(xdg_surface) orelse return error.UnableToGetXdgTopLevel;
|
||||||
|
|
||||||
// TODO: handle this return value
|
// TODO: handle this return value
|
||||||
_ = c.xdg_surface_add_listener(xdg_surface, &xdg_surface_listener.listener, linux);
|
_ = c.xdg_surface_add_listener(xdg_surface, &xdg_surface_listener.listener, linux);
|
||||||
|
|
||||||
// TODO: handle this return value
|
// TODO: handle this return value
|
||||||
_ = c.xdg_toplevel_add_listener(toplevel, &xdg_toplevel_listener.listener, linux);
|
_ = c.xdg_toplevel_add_listener(wl.toplevel, &xdg_toplevel_listener.listener, linux);
|
||||||
|
|
||||||
// Commit changes to surface
|
// Commit changes to surface
|
||||||
c.wl_surface_commit(wl.surface);
|
c.wl_surface_commit(wl.surface);
|
||||||
|
|
@ -153,11 +155,11 @@ pub fn init(
|
||||||
// This space intentionally left blank
|
// This space intentionally left blank
|
||||||
}
|
}
|
||||||
|
|
||||||
c.xdg_toplevel_set_title(toplevel, options.title);
|
c.xdg_toplevel_set_title(wl.toplevel, options.title);
|
||||||
|
|
||||||
const decoration = c.zxdg_decoration_manager_v1_get_toplevel_decoration(
|
const decoration = c.zxdg_decoration_manager_v1_get_toplevel_decoration(
|
||||||
wl.interfaces.zxdg_decoration_manager_v1,
|
wl.interfaces.zxdg_decoration_manager_v1,
|
||||||
toplevel,
|
wl.toplevel,
|
||||||
) orelse return error.UnableToGetToplevelDecoration;
|
) orelse return error.UnableToGetToplevelDecoration;
|
||||||
|
|
||||||
c.zxdg_toplevel_decoration_v1_set_mode(decoration, c.ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
|
c.zxdg_toplevel_decoration_v1_set_mode(decoration, c.ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
|
||||||
|
|
@ -204,6 +206,10 @@ pub fn update(wl: *Wayland, linux: *Linux) !void {
|
||||||
wl.core.input.tick();
|
wl.core.input.tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn setTitle(wl: *Wayland, title: [:0]const u8) void {
|
||||||
|
c.xdg_toplevel_set_title(wl.toplevel, title);
|
||||||
|
}
|
||||||
|
|
||||||
const LibXkbCommon = struct {
|
const LibXkbCommon = struct {
|
||||||
handle: std.DynLib,
|
handle: std.DynLib,
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -265,6 +265,10 @@ pub fn update(x11: *X11, linux: *Linux) !void {
|
||||||
x11.core.input.tick();
|
x11.core.input.tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn setTitle(x11: *X11, title: [:0]const u8) void {
|
||||||
|
_ = x11.libx11.XStoreName(x11.display, x11.window, title);
|
||||||
|
}
|
||||||
|
|
||||||
const LibX11 = struct {
|
const LibX11 = struct {
|
||||||
handle: std.DynLib,
|
handle: std.DynLib,
|
||||||
XInitThreads: *const @TypeOf(c.XInitThreads),
|
XInitThreads: *const @TypeOf(c.XInitThreads),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue