From f57f42d2e86d3c44b662ea0f587fb74d3f85ff4b Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 7 Feb 2017 17:13:29 +0100 Subject: Add functionality for desktop renaming. --- bindings.lua | 19 ++++++++++++++----- desktop.lua | 1 + pager.lua | 6 ++++++ rc.lua | 2 +- workspace.lua | 14 +++++++++++--- 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/bindings.lua b/bindings.lua index 455a5fd..be43176 100644 --- a/bindings.lua +++ b/bindings.lua @@ -68,8 +68,6 @@ function M.create(workspace) awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end), awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end), - awful.key({ modkey, "Control" }, "n", awful.client.restore), - -- Prompt awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end), @@ -79,7 +77,19 @@ function M.create(workspace) mypromptbox[mouse.screen].widget, awful.util.eval, nil, awful.util.getdir("cache") .. "/history_eval") - end) + end), + + awful.key({ modkey }, "n", + function() + awful.prompt.run({ prompt = "Rename desktop: " }, + mypromptbox[mouse.screen].widget, + function(input) + if input then + local cur_desk = workspace.screen_state[mouse.screen].desktop + workspace:rename_desktop(cur_desk, input) + end + end) + end) ) -- Bind all key numbers to tags. @@ -117,7 +127,7 @@ function M.create(workspace) function () local screen = mouse.screen if workspace.desktops[i] == nil then - workspace:add_desktop("Desktop " .. i, 10) + workspace:add_desktop(i, "Desktop " .. i, 10) end workspace:view(screen, i) end), @@ -137,7 +147,6 @@ function M.create(workspace) awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ), awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end), awful.key({ modkey, }, "o", awful.client.movetoscreen ), - awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end), awful.key({ modkey, }, "m", function (c) c.maximized_horizontal = not c.maximized_horizontal diff --git a/desktop.lua b/desktop.lua index d714dc9..38c890b 100644 --- a/desktop.lua +++ b/desktop.lua @@ -25,6 +25,7 @@ local function desktop_new(idx, name, nb_pages, layout) local ret = object() ret:add_signal("page:view") + ret:add_signal("desktop:name") ret.show = desktop_show diff --git a/pager.lua b/pager.lua index 1cef725..d2e67d4 100644 --- a/pager.lua +++ b/pager.lua @@ -114,6 +114,12 @@ local function pager_set_desktop(self, desktop) local title_fg = beautiful.fg_focus or "#000000" local title_container = wibox.widget.background(title, title_bg) title_container:set_fg(title_fg) + + self.desktop:connect_signal("desktop:name", + function(desktop, name) + title:set_text(name) + end) + self:add(title_container) for i = 1, nb_pages do diff --git a/rc.lua b/rc.lua index eaf9de0..1cfaebe 100644 --- a/rc.lua +++ b/rc.lua @@ -55,7 +55,7 @@ local layouts = -- {{{ Tags workspace = workspace.Workspace:new(layouts) -workspace:add_desktop("main", 10) +workspace:add_desktop(1, "main", 10) -- }}} -- Menubar configuration diff --git a/workspace.lua b/workspace.lua index 537345d..0ac91c3 100644 --- a/workspace.lua +++ b/workspace.lua @@ -6,12 +6,17 @@ local object = require("gears.object") local Workspace = {} -function Workspace:add_desktop(name, nb_pages) - idx = #self.desktops + 1 +function Workspace:add_desktop(idx, name, nb_pages) self.desktops[idx] = desktop.new(idx, name, nb_pages, self.layouts[1]) return idx end +function Workspace:rename_desktop(idx, name) + local desk = self.desktops[idx] + desk.name = name + desk:emit_signal("desktop:name", name) +end + function Workspace:_apply_state() orig_focus = mouse.screen @@ -105,7 +110,10 @@ end function Workspace:move_client(client, desk, page) print("move to " .. desk .. "/" .. page) - awful.client.movetotag(self.desktops[desk].pages[page], client) + local dst_page = self.desktops[desk].pages[page] + local dst_screen = awful.tag.getscreen(dst_page) + awful.client.movetoscreen(client, dst_screen) + awful.client.movetotag(dst_page, client) end function Workspace:new(layouts) -- cgit v1.2.3