Implement tag assignment
There are a few bugs with this, but the core logic is sound
This commit is contained in:
		@ -98,8 +98,8 @@ pub const Cursor = struct {
 | 
				
			|||||||
        // Move the grabbed view to the new position.
 | 
					        // Move the grabbed view to the new position.
 | 
				
			||||||
        // TODO: log on null
 | 
					        // TODO: log on null
 | 
				
			||||||
        if (self.grabbed_view) |view| {
 | 
					        if (self.grabbed_view) |view| {
 | 
				
			||||||
            view.current_state.x = @floatToInt(c_int, self.wlr_cursor.x - self.grab_x);
 | 
					            view.current_box.x = @floatToInt(c_int, self.wlr_cursor.x - self.grab_x);
 | 
				
			||||||
            view.current_state.y = @floatToInt(c_int, self.wlr_cursor.y - self.grab_y);
 | 
					            view.current_box.y = @floatToInt(c_int, self.wlr_cursor.y - self.grab_y);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -119,8 +119,8 @@ pub const Cursor = struct {
 | 
				
			|||||||
        const dx: f64 = self.wlr_cursor.x - self.grab_x;
 | 
					        const dx: f64 = self.wlr_cursor.x - self.grab_x;
 | 
				
			||||||
        const dy: f64 = self.wlr_cursor.y - self.grab_y;
 | 
					        const dy: f64 = self.wlr_cursor.y - self.grab_y;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var x: f64 = @intToFloat(f64, view.current_state.x);
 | 
					        var x: f64 = @intToFloat(f64, view.current_box.x);
 | 
				
			||||||
        var y: f64 = @intToFloat(f64, view.current_state.y);
 | 
					        var y: f64 = @intToFloat(f64, view.current_box.y);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var width = @intToFloat(f64, self.grab_width);
 | 
					        var width = @intToFloat(f64, self.grab_width);
 | 
				
			||||||
        var height = @intToFloat(f64, self.grab_height);
 | 
					        var height = @intToFloat(f64, self.grab_height);
 | 
				
			||||||
@ -143,8 +143,8 @@ pub const Cursor = struct {
 | 
				
			|||||||
        } else if (self.resize_edges & @intCast(u32, c.WLR_EDGE_RIGHT) != 0) {
 | 
					        } else if (self.resize_edges & @intCast(u32, c.WLR_EDGE_RIGHT) != 0) {
 | 
				
			||||||
            width += dx;
 | 
					            width += dx;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        view.current_state.x = @floatToInt(c_int, x);
 | 
					        view.current_box.x = @floatToInt(c_int, x);
 | 
				
			||||||
        view.current_state.y = @floatToInt(c_int, y);
 | 
					        view.current_box.y = @floatToInt(c_int, y);
 | 
				
			||||||
        _ = c.wlr_xdg_toplevel_set_size(
 | 
					        _ = c.wlr_xdg_toplevel_set_size(
 | 
				
			||||||
            view.wlr_xdg_surface,
 | 
					            view.wlr_xdg_surface,
 | 
				
			||||||
            @floatToInt(u32, width),
 | 
					            @floatToInt(u32, width),
 | 
				
			||||||
 | 
				
			|||||||
@ -81,11 +81,29 @@ pub const Keyboard = struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Translate libinput keycode -> xkbcommon
 | 
					        // Translate libinput keycode -> xkbcommon
 | 
				
			||||||
        const keycode = event.keycode + 8;
 | 
					        const keycode = event.keycode + 8;
 | 
				
			||||||
        // Get a list of keysyms based on the keymap for this keyboard
 | 
					
 | 
				
			||||||
        var syms: ?[*]c.xkb_keysym_t = undefined;
 | 
					        // Get a list of keysyms as xkb reports them
 | 
				
			||||||
        const nsyms = c.xkb_state_key_get_syms(wlr_keyboard.xkb_state, keycode, &syms);
 | 
					        var translated_keysyms: ?[*]c.xkb_keysym_t = undefined;
 | 
				
			||||||
 | 
					        const translated_keysyms_len = c.xkb_state_key_get_syms(
 | 
				
			||||||
 | 
					            wlr_keyboard.xkb_state,
 | 
				
			||||||
 | 
					            keycode,
 | 
				
			||||||
 | 
					            &translated_keysyms,
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Get a list of keysyms ignoring modifiers (e.g. 1 instead of !)
 | 
				
			||||||
 | 
					        // Important for bindings like Mod+Shift+1
 | 
				
			||||||
 | 
					        var raw_keysyms: ?[*]c.xkb_keysym_t = undefined;
 | 
				
			||||||
 | 
					        const layout_index = c.xkb_state_key_get_layout(wlr_keyboard.xkb_state, keycode);
 | 
				
			||||||
 | 
					        const raw_keysyms_len = c.xkb_keymap_key_get_syms_by_level(
 | 
				
			||||||
 | 
					            wlr_keyboard.keymap,
 | 
				
			||||||
 | 
					            keycode,
 | 
				
			||||||
 | 
					            layout_index,
 | 
				
			||||||
 | 
					            0,
 | 
				
			||||||
 | 
					            &raw_keysyms,
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var handled = false;
 | 
					        var handled = false;
 | 
				
			||||||
 | 
					        // TODO: These modifiers aren't properly handled, see sway's code
 | 
				
			||||||
        const modifiers = c.wlr_keyboard_get_modifiers(wlr_keyboard);
 | 
					        const modifiers = c.wlr_keyboard_get_modifiers(wlr_keyboard);
 | 
				
			||||||
        if (modifiers & @intCast(u32, c.WLR_MODIFIER_LOGO) != 0 and
 | 
					        if (modifiers & @intCast(u32, c.WLR_MODIFIER_LOGO) != 0 and
 | 
				
			||||||
            event.state == c.enum_wlr_key_state.WLR_KEY_PRESSED)
 | 
					            event.state == c.enum_wlr_key_state.WLR_KEY_PRESSED)
 | 
				
			||||||
@ -93,12 +111,20 @@ pub const Keyboard = struct {
 | 
				
			|||||||
            // If mod is held down and this button was _pressed_, we attempt to
 | 
					            // If mod is held down and this button was _pressed_, we attempt to
 | 
				
			||||||
            // process it as a compositor keybinding.
 | 
					            // process it as a compositor keybinding.
 | 
				
			||||||
            var i: usize = 0;
 | 
					            var i: usize = 0;
 | 
				
			||||||
            while (i < nsyms) {
 | 
					            while (i < translated_keysyms_len) : (i += 1) {
 | 
				
			||||||
                handled = keyboard.seat.server.handleKeybinding(syms.?[i], modifiers);
 | 
					                if (keyboard.seat.server.handleKeybinding(translated_keysyms.?[i], modifiers)) {
 | 
				
			||||||
                if (handled) {
 | 
					                    handled = true;
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                i += 1;
 | 
					            }
 | 
				
			||||||
 | 
					            if (!handled) {
 | 
				
			||||||
 | 
					                i = 0;
 | 
				
			||||||
 | 
					                while (i < raw_keysyms_len) : (i += 1) {
 | 
				
			||||||
 | 
					                    if (keyboard.seat.server.handleKeybinding(raw_keysyms.?[i], modifiers)) {
 | 
				
			||||||
 | 
					                        handled = true;
 | 
				
			||||||
 | 
					                        break;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -86,7 +86,7 @@ pub const Output = struct {
 | 
				
			|||||||
            const view = &node.data;
 | 
					            const view = &node.data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Only render currently visible views
 | 
					            // Only render currently visible views
 | 
				
			||||||
            if (!view.isVisible(output.root.current_focused_tags)) {
 | 
					            if (view.current_tags & output.root.current_focused_tags == 0) {
 | 
				
			||||||
                continue;
 | 
					                continue;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -118,10 +118,10 @@ pub const Output = struct {
 | 
				
			|||||||
        // and need to render that buffer until the transaction is complete.
 | 
					        // and need to render that buffer until the transaction is complete.
 | 
				
			||||||
        if (view.stashed_buffer) |buffer| {
 | 
					        if (view.stashed_buffer) |buffer| {
 | 
				
			||||||
            var box = c.wlr_box{
 | 
					            var box = c.wlr_box{
 | 
				
			||||||
                .x = view.current_state.x,
 | 
					                .x = view.current_box.x,
 | 
				
			||||||
                .y = view.current_state.y,
 | 
					                .y = view.current_box.y,
 | 
				
			||||||
                .width = @intCast(c_int, view.current_state.width),
 | 
					                .width = @intCast(c_int, view.current_box.width),
 | 
				
			||||||
                .height = @intCast(c_int, view.current_state.height),
 | 
					                .height = @intCast(c_int, view.current_box.height),
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Scale the box to the output's current scaling factor
 | 
					            // Scale the box to the output's current scaling factor
 | 
				
			||||||
@ -185,8 +185,8 @@ pub const Output = struct {
 | 
				
			|||||||
        var ox: f64 = 0.0;
 | 
					        var ox: f64 = 0.0;
 | 
				
			||||||
        var oy: f64 = 0.0;
 | 
					        var oy: f64 = 0.0;
 | 
				
			||||||
        c.wlr_output_layout_output_coords(view.root.wlr_output_layout, output, &ox, &oy);
 | 
					        c.wlr_output_layout_output_coords(view.root.wlr_output_layout, output, &ox, &oy);
 | 
				
			||||||
        ox += @intToFloat(f64, view.current_state.x + sx);
 | 
					        ox += @intToFloat(f64, view.current_box.x + sx);
 | 
				
			||||||
        oy += @intToFloat(f64, view.current_state.y + sy);
 | 
					        oy += @intToFloat(f64, view.current_box.y + sy);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var box = c.wlr_box{
 | 
					        var box = c.wlr_box{
 | 
				
			||||||
            .x = @floatToInt(c_int, ox),
 | 
					            .x = @floatToInt(c_int, ox),
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										44
									
								
								src/root.zig
									
									
									
									
									
								
							
							
						
						
									
										44
									
								
								src/root.zig
									
									
									
									
									
								
							@ -105,7 +105,7 @@ pub const Root = struct {
 | 
				
			|||||||
            var it = @fieldParentPtr(std.TailQueue(View).Node, "data", current_focus).next;
 | 
					            var it = @fieldParentPtr(std.TailQueue(View).Node, "data", current_focus).next;
 | 
				
			||||||
            while (it) |node| : (it = node.next) {
 | 
					            while (it) |node| : (it = node.next) {
 | 
				
			||||||
                const view = &node.data;
 | 
					                const view = &node.data;
 | 
				
			||||||
                if (view.isVisible(self.current_focused_tags)) {
 | 
					                if (view.current_tags & self.current_focused_tags != 0) {
 | 
				
			||||||
                    view.focus(view.wlr_xdg_surface.surface);
 | 
					                    view.focus(view.wlr_xdg_surface.surface);
 | 
				
			||||||
                    return;
 | 
					                    return;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
@ -117,7 +117,7 @@ pub const Root = struct {
 | 
				
			|||||||
        var it = self.views.first;
 | 
					        var it = self.views.first;
 | 
				
			||||||
        while (it) |node| : (it = node.next) {
 | 
					        while (it) |node| : (it = node.next) {
 | 
				
			||||||
            const view = &node.data;
 | 
					            const view = &node.data;
 | 
				
			||||||
            if (view.isVisible(self.current_focused_tags)) {
 | 
					            if (view.current_tags & self.current_focused_tags != 0) {
 | 
				
			||||||
                view.focus(view.wlr_xdg_surface.surface);
 | 
					                view.focus(view.wlr_xdg_surface.surface);
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@ -132,7 +132,7 @@ pub const Root = struct {
 | 
				
			|||||||
            var it = @fieldParentPtr(std.TailQueue(View).Node, "data", current_focus).prev;
 | 
					            var it = @fieldParentPtr(std.TailQueue(View).Node, "data", current_focus).prev;
 | 
				
			||||||
            while (it) |node| : (it = node.prev) {
 | 
					            while (it) |node| : (it = node.prev) {
 | 
				
			||||||
                const view = &node.data;
 | 
					                const view = &node.data;
 | 
				
			||||||
                if (view.isVisible(self.current_focused_tags)) {
 | 
					                if (view.current_tags & self.current_focused_tags != 0) {
 | 
				
			||||||
                    view.focus(view.wlr_xdg_surface.surface);
 | 
					                    view.focus(view.wlr_xdg_surface.surface);
 | 
				
			||||||
                    return;
 | 
					                    return;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
@ -144,7 +144,7 @@ pub const Root = struct {
 | 
				
			|||||||
        var it = self.views.last;
 | 
					        var it = self.views.last;
 | 
				
			||||||
        while (it) |node| : (it = node.prev) {
 | 
					        while (it) |node| : (it = node.prev) {
 | 
				
			||||||
            const view = &node.data;
 | 
					            const view = &node.data;
 | 
				
			||||||
            if (view.isVisible(self.current_focused_tags)) {
 | 
					            if (view.current_tags & self.current_focused_tags != 0) {
 | 
				
			||||||
                view.focus(view.wlr_xdg_surface.surface);
 | 
					                view.focus(view.wlr_xdg_surface.surface);
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@ -152,12 +152,12 @@ pub const Root = struct {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // TODO: obsolete this function by using a better data structure
 | 
					    // TODO: obsolete this function by using a better data structure
 | 
				
			||||||
    pub fn visibleCount(self: Self, tags: u32) u32 {
 | 
					    fn visibleCount(self: Self, tags: u32) u32 {
 | 
				
			||||||
        var count: u32 = 0;
 | 
					        var count: u32 = 0;
 | 
				
			||||||
        var it = self.views.first;
 | 
					        var it = self.views.first;
 | 
				
			||||||
        while (it) |node| : (it = node.next) {
 | 
					        while (it) |node| : (it = node.next) {
 | 
				
			||||||
            const view = &node.data;
 | 
					            const view = &node.data;
 | 
				
			||||||
            if (view.isVisible(tags)) {
 | 
					            if (view.current_tags & tags != 0) {
 | 
				
			||||||
                count += 1;
 | 
					                count += 1;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -165,12 +165,12 @@ pub const Root = struct {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn arrange(self: *Self) void {
 | 
					    pub fn arrange(self: *Self) void {
 | 
				
			||||||
        const tags = if (self.pending_focused_tags) |tags|
 | 
					        const root_tags = if (self.pending_focused_tags) |tags|
 | 
				
			||||||
            tags
 | 
					            tags
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
            self.current_focused_tags;
 | 
					            self.current_focused_tags;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const visible_count = self.visibleCount(tags);
 | 
					        const visible_count = self.visibleCount(root_tags);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const master_count = util.min(u32, self.master_count, visible_count);
 | 
					        const master_count = util.min(u32, self.master_count, visible_count);
 | 
				
			||||||
        const slave_count = if (master_count >= visible_count) 0 else visible_count - master_count;
 | 
					        const slave_count = if (master_count >= visible_count) 0 else visible_count - master_count;
 | 
				
			||||||
@ -196,7 +196,11 @@ pub const Root = struct {
 | 
				
			|||||||
        while (it) |node| : (it = node.next) {
 | 
					        while (it) |node| : (it = node.next) {
 | 
				
			||||||
            const view = &node.data;
 | 
					            const view = &node.data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!view.isVisible(tags)) {
 | 
					            if (view.pending_tags) |tags| {
 | 
				
			||||||
 | 
					                if (root_tags & tags == 0) {
 | 
				
			||||||
 | 
					                    continue;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            } else if (view.current_tags & root_tags == 0) {
 | 
				
			||||||
                continue;
 | 
					                continue;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -205,22 +209,20 @@ pub const Root = struct {
 | 
				
			|||||||
                const master_height = @divTrunc(@intCast(u32, output_box.height), master_count);
 | 
					                const master_height = @divTrunc(@intCast(u32, output_box.height), master_count);
 | 
				
			||||||
                const master_height_rem = @intCast(u32, output_box.height) % master_count;
 | 
					                const master_height_rem = @intCast(u32, output_box.height) % master_count;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                view.pending_state = View.State{
 | 
					                view.pending_box = View.Box{
 | 
				
			||||||
                    .x = 0,
 | 
					                    .x = 0,
 | 
				
			||||||
                    .y = @intCast(i32, i * master_height +
 | 
					                    .y = @intCast(i32, i * master_height +
 | 
				
			||||||
                        if (i > 0) master_height_rem else 0),
 | 
					                        if (i > 0) master_height_rem else 0),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    .width = master_column_width,
 | 
					                    .width = master_column_width,
 | 
				
			||||||
                    .height = master_height + if (i == 0) master_height_rem else 0,
 | 
					                    .height = master_height + if (i == 0) master_height_rem else 0,
 | 
				
			||||||
 | 
					 | 
				
			||||||
                    .tags = view.current_state.tags,
 | 
					 | 
				
			||||||
                };
 | 
					                };
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                // Add the remainder to the first slave to ensure every pixel of height is used
 | 
					                // Add the remainder to the first slave to ensure every pixel of height is used
 | 
				
			||||||
                const slave_height = @divTrunc(@intCast(u32, output_box.height), slave_count);
 | 
					                const slave_height = @divTrunc(@intCast(u32, output_box.height), slave_count);
 | 
				
			||||||
                const slave_height_rem = @intCast(u32, output_box.height) % slave_count;
 | 
					                const slave_height_rem = @intCast(u32, output_box.height) % slave_count;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                view.pending_state = View.State{
 | 
					                view.pending_box = View.Box{
 | 
				
			||||||
                    .x = @intCast(i32, master_column_width),
 | 
					                    .x = @intCast(i32, master_column_width),
 | 
				
			||||||
                    .y = @intCast(i32, (i - master_count) * slave_height +
 | 
					                    .y = @intCast(i32, (i - master_count) * slave_height +
 | 
				
			||||||
                        if (i > master_count) slave_height_rem else 0),
 | 
					                        if (i > master_count) slave_height_rem else 0),
 | 
				
			||||||
@ -228,8 +230,6 @@ pub const Root = struct {
 | 
				
			|||||||
                    .width = slave_column_width,
 | 
					                    .width = slave_column_width,
 | 
				
			||||||
                    .height = slave_height +
 | 
					                    .height = slave_height +
 | 
				
			||||||
                        if (i == master_count) slave_height_rem else 0,
 | 
					                        if (i == master_count) slave_height_rem else 0,
 | 
				
			||||||
 | 
					 | 
				
			||||||
                    .tags = view.current_state.tags,
 | 
					 | 
				
			||||||
                };
 | 
					                };
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -314,7 +314,7 @@ pub const Root = struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // If there were pending focused tags, make them the current focus
 | 
					        // If there were pending focused tags, make them the current focus
 | 
				
			||||||
        if (self.pending_focused_tags) |tags| {
 | 
					        if (self.pending_focused_tags) |tags| {
 | 
				
			||||||
            Log.Debug.log("changing current focus: {b:0>10} to {b:0>10}\n", .{ self.current_focused_tags, tags });
 | 
					            Log.Debug.log("changing current focus: {b:0>10} to {b:0>10}", .{ self.current_focused_tags, tags });
 | 
				
			||||||
            self.current_focused_tags = tags;
 | 
					            self.current_focused_tags = tags;
 | 
				
			||||||
            self.pending_focused_tags = null;
 | 
					            self.pending_focused_tags = null;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -325,10 +325,16 @@ pub const Root = struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            // Ensure that all pending state is cleared
 | 
					            // Ensure that all pending state is cleared
 | 
				
			||||||
            view.pending_serial = null;
 | 
					            view.pending_serial = null;
 | 
				
			||||||
            if (view.pending_state) |state| {
 | 
					            if (view.pending_box) |state| {
 | 
				
			||||||
                view.current_state = state;
 | 
					                view.current_box = state;
 | 
				
			||||||
                view.pending_state = null;
 | 
					                view.pending_box = null;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (view.pending_tags) |tags| {
 | 
				
			||||||
 | 
					                view.current_tags = tags;
 | 
				
			||||||
 | 
					                view.pending_tags = null;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            view.dropStashedBuffer();
 | 
					            view.dropStashedBuffer();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -136,6 +136,42 @@ pub const Server = struct {
 | 
				
			|||||||
                    const child = std.ChildProcess.init(&argv, std.heap.c_allocator) catch unreachable;
 | 
					                    const child = std.ChildProcess.init(&argv, std.heap.c_allocator) catch unreachable;
 | 
				
			||||||
                    std.ChildProcess.spawn(child) catch unreachable;
 | 
					                    std.ChildProcess.spawn(child) catch unreachable;
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
 | 
					                c.XKB_KEY_1 => {
 | 
				
			||||||
 | 
					                    if (self.root.focused_view) |view| {
 | 
				
			||||||
 | 
					                        view.pending_tags = 1 << 0;
 | 
				
			||||||
 | 
					                        self.root.arrange();
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                c.XKB_KEY_2 => {
 | 
				
			||||||
 | 
					                    if (self.root.focused_view) |view| {
 | 
				
			||||||
 | 
					                        view.pending_tags = 1 << 1;
 | 
				
			||||||
 | 
					                        self.root.arrange();
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                c.XKB_KEY_3 => {
 | 
				
			||||||
 | 
					                    if (self.root.focused_view) |view| {
 | 
				
			||||||
 | 
					                        view.pending_tags = 1 << 2;
 | 
				
			||||||
 | 
					                        self.root.arrange();
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                c.XKB_KEY_4 => {
 | 
				
			||||||
 | 
					                    if (self.root.focused_view) |view| {
 | 
				
			||||||
 | 
					                        view.pending_tags = 1 << 3;
 | 
				
			||||||
 | 
					                        self.root.arrange();
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                c.XKB_KEY_5 => {
 | 
				
			||||||
 | 
					                    if (self.root.focused_view) |view| {
 | 
				
			||||||
 | 
					                        view.pending_tags = 1 << 4;
 | 
				
			||||||
 | 
					                        self.root.arrange();
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                c.XKB_KEY_6 => {
 | 
				
			||||||
 | 
					                    if (self.root.focused_view) |view| {
 | 
				
			||||||
 | 
					                        view.pending_tags = 1 << 5;
 | 
				
			||||||
 | 
					                        self.root.arrange();
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
                else => return false,
 | 
					                else => return false,
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										41
									
								
								src/view.zig
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								src/view.zig
									
									
									
									
									
								
							@ -11,16 +11,18 @@ pub const View = struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    mapped: bool,
 | 
					    mapped: bool,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub const State = struct {
 | 
					    pub const Box = struct {
 | 
				
			||||||
        x: i32,
 | 
					        x: i32,
 | 
				
			||||||
        y: i32,
 | 
					        y: i32,
 | 
				
			||||||
        width: u32,
 | 
					        width: u32,
 | 
				
			||||||
        height: u32,
 | 
					        height: u32,
 | 
				
			||||||
        tags: u32,
 | 
					 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    current_state: State,
 | 
					    current_box: Box,
 | 
				
			||||||
    pending_state: ?State,
 | 
					    pending_box: ?Box,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    current_tags: u32,
 | 
				
			||||||
 | 
					    pending_tags: ?u32,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pending_serial: ?u32,
 | 
					    pending_serial: ?u32,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -45,14 +47,16 @@ pub const View = struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        self.mapped = false;
 | 
					        self.mapped = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.current_state = State{
 | 
					        self.current_box = Box{
 | 
				
			||||||
            .x = 0,
 | 
					            .x = 0,
 | 
				
			||||||
            .y = 0,
 | 
					            .y = 0,
 | 
				
			||||||
            .height = 0,
 | 
					            .height = 0,
 | 
				
			||||||
            .width = 0,
 | 
					            .width = 0,
 | 
				
			||||||
            .tags = tags,
 | 
					 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
        self.pending_state = null;
 | 
					        self.pending_box = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.current_tags = tags;
 | 
				
			||||||
 | 
					        self.pending_tags = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.pending_serial = null;
 | 
					        self.pending_serial = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -76,20 +80,20 @@ pub const View = struct {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn needsConfigure(self: Self) bool {
 | 
					    pub fn needsConfigure(self: Self) bool {
 | 
				
			||||||
        if (self.pending_state) |pending_state| {
 | 
					        if (self.pending_box) |pending_box| {
 | 
				
			||||||
            return pending_state.width != self.current_state.width or
 | 
					            return pending_box.width != self.current_box.width or
 | 
				
			||||||
                pending_state.height != self.current_state.height;
 | 
					                pending_box.height != self.current_box.height;
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn configurePending(self: *Self) void {
 | 
					    pub fn configurePending(self: *Self) void {
 | 
				
			||||||
        if (self.pending_state) |pending_state| {
 | 
					        if (self.pending_box) |pending_box| {
 | 
				
			||||||
            self.pending_serial = c.wlr_xdg_toplevel_set_size(
 | 
					            self.pending_serial = c.wlr_xdg_toplevel_set_size(
 | 
				
			||||||
                self.wlr_xdg_surface,
 | 
					                self.wlr_xdg_surface,
 | 
				
			||||||
                pending_state.width,
 | 
					                pending_box.width,
 | 
				
			||||||
                pending_state.height,
 | 
					                pending_box.height,
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            // TODO: log warning
 | 
					            // TODO: log warning
 | 
				
			||||||
@ -133,11 +137,6 @@ pub const View = struct {
 | 
				
			|||||||
        view.root.arrange();
 | 
					        view.root.arrange();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// Returns true if the view is shown given the current state of tags
 | 
					 | 
				
			||||||
    pub fn isVisible(self: Self, tags: u32) bool {
 | 
					 | 
				
			||||||
        return tags & self.current_state.tags != 0;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    fn handleUnmap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
 | 
					    fn handleUnmap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
 | 
				
			||||||
        const view = @fieldParentPtr(View, "listen_unmap", listener.?);
 | 
					        const view = @fieldParentPtr(View, "listen_unmap", listener.?);
 | 
				
			||||||
        const root = view.root;
 | 
					        const root = view.root;
 | 
				
			||||||
@ -236,11 +235,11 @@ pub const View = struct {
 | 
				
			|||||||
        // coordinates lx and ly (in output Layout Coordinates). If so, it sets the
 | 
					        // coordinates lx and ly (in output Layout Coordinates). If so, it sets the
 | 
				
			||||||
        // surface pointer to that wlr_surface and the sx and sy coordinates to the
 | 
					        // surface pointer to that wlr_surface and the sx and sy coordinates to the
 | 
				
			||||||
        // coordinates relative to that surface's top-left corner.
 | 
					        // coordinates relative to that surface's top-left corner.
 | 
				
			||||||
        const view_sx = lx - @intToFloat(f64, self.current_state.x);
 | 
					        const view_sx = lx - @intToFloat(f64, self.current_box.x);
 | 
				
			||||||
        const view_sy = ly - @intToFloat(f64, self.current_state.y);
 | 
					        const view_sy = ly - @intToFloat(f64, self.current_box.y);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // This variable seems to have been unsued in TinyWL
 | 
					        // This variable seems to have been unsued in TinyWL
 | 
				
			||||||
        // struct wlr_surface_state *state = &view->xdg_surface->surface->current;
 | 
					        // struct wlr_surface_box *state = &view->xdg_surface->surface->current;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var _sx: f64 = undefined;
 | 
					        var _sx: f64 = undefined;
 | 
				
			||||||
        var _sy: f64 = undefined;
 | 
					        var _sy: f64 = undefined;
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user