From 871204a041cddf127149ef8e5fd1d5eb54784f51 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 26 Oct 2021 18:52:13 +0200 Subject: bindings: factor out swapping two screens --- bindings.lua | 36 +++--------------------------------- workspace.lua | 11 +++++++++++ 2 files changed, 14 insertions(+), 33 deletions(-) diff --git a/bindings.lua b/bindings.lua index 087e4c3..e1b68c8 100644 --- a/bindings.lua +++ b/bindings.lua @@ -140,39 +140,9 @@ function M.create(workspace) end), -- swap two screens - awful.key({ modkey, "Control" }, "q", - function () - local screen_dst = mouse.screen - local screen_src = utils.screen_physical(1) - if screen_src ~= screen_dst then - local desk_idx = workspace.screen_state[screen_src].desktop_idx - local page_idx = workspace.screen_state[screen_src].page_idx - workspace:view(screen_dst, desk_idx, page_idx) - end - timer.delayed_call(awful.screen.focus, screen_src) - end), - awful.key({ modkey, "Control" }, "w", - function () - local screen_dst = mouse.screen - local screen_src = utils.screen_physical(2) - if screen_src ~= screen_dst then - local desk_idx = workspace.screen_state[screen_src].desktop_idx - local page_idx = workspace.screen_state[screen_src].page_idx - workspace:view(screen_dst, desk_idx, page_idx) - end - timer.delayed_call(awful.screen.focus, screen_src) - end), - awful.key({ modkey, "Control" }, "e", - function () - local screen_dst = mouse.screen - local screen_src = utils.screen_physical(3) - if screen_src ~= screen_dst then - local desk_idx = workspace.screen_state[screen_src].desktop_idx - local page_idx = workspace.screen_state[screen_src].page_idx - workspace:view(screen_dst, desk_idx, page_idx) - end - timer.delayed_call(awful.screen.focus, screen_src) - end), + awful.key({ modkey, "Control" }, "q", function() workspace:swap_screens(1) end), + awful.key({ modkey, "Control" }, "w", function() workspace:swap_screens(2) end), + awful.key({ modkey, "Control" }, "e", function() workspace:swap_screens(3) end), -- Prompt awful.key({ modkey }, "n", diff --git a/workspace.lua b/workspace.lua index 63fad94..654b118 100644 --- a/workspace.lua +++ b/workspace.lua @@ -4,6 +4,7 @@ local awful = require("awful") local object = require("gears.object") local stack = require("stack") local timer = require("gears.timer") +local utils = require("utils") local Workspace = {} @@ -168,6 +169,16 @@ function Workspace:client_move_relative(client, offset) end end +function Workspace:swap_screens(phys_idx) + local screen_dst = mouse.screen + local screen_src = utils.screen_physical(phys_idx) + if screen_src and screen_src ~= screen_dst then + local ss = workspace.screen_state[screen_src] + self:view(screen_dst, ss.desktop_idx, ss.page_idx) + timer.delayed_call(awful.screen.focus, screen_src) + end +end + function Workspace:new(layouts) local o = setmetatable({}, self) self.__index = self -- cgit v1.2.3