mirror of
https://github.com/zoriya/gaze.git
synced 2026-06-07 11:44:51 +00:00
Add focus api
This commit is contained in:
+25
-2
@@ -1,9 +1,12 @@
|
||||
const std = @import("std");
|
||||
const gpa = std.heap.c_allocator;
|
||||
|
||||
const serv = @import("server/server.zig");
|
||||
const wlr = @import("wlroots");
|
||||
|
||||
pub fn exec(server: *serv.Server, cmd: [:0]const u8) !void {
|
||||
const Server = @import("server/server.zig").Server;
|
||||
const Client = @import("server/client.zig").Client;
|
||||
|
||||
pub fn exec(server: *Server, cmd: [:0]const u8) !void {
|
||||
var child = std.ChildProcess.init(&[_][]const u8{ "/bin/sh", "-c", cmd }, gpa);
|
||||
var env_map = try std.process.getEnvMap(gpa);
|
||||
defer env_map.deinit();
|
||||
@@ -11,3 +14,23 @@ pub fn exec(server: *serv.Server, cmd: [:0]const u8) !void {
|
||||
child.env_map = &env_map;
|
||||
try child.spawn();
|
||||
}
|
||||
|
||||
pub fn focus(server: *Server, client: *Client) !void {
|
||||
if (server.seat.keyboard_state.focused_surface) |previous_surface| {
|
||||
if (previous_surface == client.xdg_surface.surface) return;
|
||||
if (wlr.XdgSurface.tryFromWlrSurface(previous_surface)) |xdg_surface| {
|
||||
_ = xdg_surface.role_data.toplevel.?.setActivated(false);
|
||||
}
|
||||
}
|
||||
|
||||
client.scene_tree.node.raiseToTop();
|
||||
_ = client.xdg_surface.role_data.toplevel.?.setActivated(true);
|
||||
|
||||
const wlr_keyboard = server.seat.getKeyboard() orelse return;
|
||||
server.seat.keyboardNotifyEnter(
|
||||
client.xdg_surface.surface,
|
||||
&wlr_keyboard.keycodes,
|
||||
wlr_keyboard.num_keycodes,
|
||||
&wlr_keyboard.modifiers,
|
||||
);
|
||||
}
|
||||
|
||||
+13
-12
@@ -1,15 +1,15 @@
|
||||
const std = @import("std");
|
||||
const gpa = std.heap.c_allocator;
|
||||
|
||||
const Server = @import("server.zig").Server;
|
||||
const Api = @import("../commands.zig");
|
||||
|
||||
const wl = @import("wayland").server.wl;
|
||||
const wlr = @import("wlroots");
|
||||
|
||||
const gpa = std.heap.c_allocator;
|
||||
|
||||
pub const Client = struct {
|
||||
server: *Server,
|
||||
surface: *wlr.XdgSurface,
|
||||
xdg_surface: *wlr.XdgSurface,
|
||||
scene_tree: *wlr.SceneTree,
|
||||
link: wl.list.Link = undefined,
|
||||
|
||||
@@ -17,27 +17,26 @@ pub const Client = struct {
|
||||
unmap_l: wl.Listener(void) = wl.Listener(void).init(onUnmap),
|
||||
destroy_l: wl.Listener(void) = wl.Listener(void).init(onDestroy),
|
||||
|
||||
pub fn create(server: *Server, surface: *wlr.XdgSurface) !void {
|
||||
pub fn create(server: *Server, xdg_surface: *wlr.XdgSurface) !void {
|
||||
// Don't add the client to server list until it is mapped
|
||||
const self = try gpa.create(Client);
|
||||
errdefer gpa.destroy(self);
|
||||
|
||||
self.* = .{
|
||||
.server = server,
|
||||
.surface = surface,
|
||||
.scene_tree = try server.scene.tree.createSceneXdgSurface(surface),
|
||||
.xdg_surface = xdg_surface,
|
||||
.scene_tree = try server.scene.tree.createSceneXdgSurface(xdg_surface),
|
||||
};
|
||||
self.scene_tree.node.data = @intFromPtr(self);
|
||||
surface.data = @intFromPtr(self);
|
||||
xdg_surface.data = @intFromPtr(self);
|
||||
|
||||
surface.surface.events.map.add(&self.map_l);
|
||||
surface.surface.events.unmap.add(&self.unmap_l);
|
||||
surface.events.destroy.add(&self.destroy_l);
|
||||
xdg_surface.surface.events.map.add(&self.map_l);
|
||||
xdg_surface.surface.events.unmap.add(&self.unmap_l);
|
||||
xdg_surface.events.destroy.add(&self.destroy_l);
|
||||
}
|
||||
|
||||
pub fn destroy(self: *Client) void {
|
||||
self.link.remove();
|
||||
|
||||
// The client is already unlinked in the unmap event.
|
||||
self.map_l.link.remove();
|
||||
self.unmap_l.link.remove();
|
||||
self.destroy_l.link.remove();
|
||||
@@ -48,6 +47,8 @@ pub const Client = struct {
|
||||
fn onMap(listener: *wl.Listener(void)) void {
|
||||
const self = @fieldParentPtr(Client, "map_l", listener);
|
||||
self.server.clients.prepend(self);
|
||||
// TODO: remove this and add this in a lua file
|
||||
Api.focus(self.server, self) catch {};
|
||||
}
|
||||
|
||||
fn onUnmap(listener: *wl.Listener(void)) void {
|
||||
|
||||
+22
-22
@@ -218,28 +218,28 @@ const Server = struct {
|
||||
return null;
|
||||
}
|
||||
|
||||
fn focusView(server: *Server, view: *View, surface: *wlr.Surface) void {
|
||||
if (server.seat.keyboard_state.focused_surface) |previous_surface| {
|
||||
if (previous_surface == surface) return;
|
||||
if (wlr.XdgSurface.tryFromWlrSurface(previous_surface)) |xdg_surface| {
|
||||
_ = xdg_surface.role_data.toplevel.?.setActivated(false);
|
||||
}
|
||||
}
|
||||
|
||||
view.scene_tree.node.raiseToTop();
|
||||
view.link.remove();
|
||||
server.views.prepend(view);
|
||||
|
||||
_ = view.xdg_surface.role_data.toplevel.?.setActivated(true);
|
||||
|
||||
const wlr_keyboard = server.seat.getKeyboard() orelse return;
|
||||
server.seat.keyboardNotifyEnter(
|
||||
surface,
|
||||
&wlr_keyboard.keycodes,
|
||||
wlr_keyboard.num_keycodes,
|
||||
&wlr_keyboard.modifiers,
|
||||
);
|
||||
}
|
||||
// fn focusView(server: *Server, view: *View, surface: *wlr.Surface) void {
|
||||
// if (server.seat.keyboard_state.focused_surface) |previous_surface| {
|
||||
// if (previous_surface == surface) return;
|
||||
// if (wlr.XdgSurface.tryFromWlrSurface(previous_surface)) |xdg_surface| {
|
||||
// _ = xdg_surface.role_data.toplevel.?.setActivated(false);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// view.scene_tree.node.raiseToTop();
|
||||
// view.link.remove();
|
||||
// server.views.prepend(view);
|
||||
//
|
||||
// _ = view.xdg_surface.role_data.toplevel.?.setActivated(true);
|
||||
//
|
||||
// const wlr_keyboard = server.seat.getKeyboard() orelse return;
|
||||
// server.seat.keyboardNotifyEnter(
|
||||
// surface,
|
||||
// &wlr_keyboard.keycodes,
|
||||
// wlr_keyboard.num_keycodes,
|
||||
// &wlr_keyboard.modifiers,
|
||||
// );
|
||||
// }
|
||||
|
||||
// fn newInput(listener: *wl.Listener(*wlr.InputDevice), device: *wlr.InputDevice) void {
|
||||
// const server = @fieldParentPtr(Server, "new_input", listener);
|
||||
|
||||
Reference in New Issue
Block a user