From 044a445cdc2f25f9f069eb95113812cd19f1c0fe Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 10 Apr 2020 16:14:11 +0200 Subject: workspace: merge with desktop The desktop API is not really standalone anyway. --- workspace.lua | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'workspace.lua') diff --git a/workspace.lua b/workspace.lua index ad985df..768293f 100644 --- a/workspace.lua +++ b/workspace.lua @@ -1,13 +1,42 @@ local M = {} local awful = require("awful") -local desktop = require("desktop") local object = require("gears.object") local Workspace = {} +local function desktop_show(self, screen, page_idx) + if page_idx == nil then + local page_hist = self.page_history[screen] + if page_hist ~= nil then + page_idx = page_hist + else + page_idx = 1 + end + end + + local page = self.pages[page_idx] + + if page then + self.page_history[screen] = page_idx + end + return page_idx +end + function Workspace:add_desktop(idx, name, nb_pages) - self.desktops[idx] = desktop.new(idx, name, nb_pages, self.layouts[1]) + local desk = object() + + desk.name = name + + desk.pages = {} + for i = 1, nb_pages do + desk.pages[i] = awful.tag.add(name .. i, { layout = self.layouts[1] }) + end + + -- page_history[i] is the last page viewed on screen i + desk.page_history = {} + + self.desktops[idx] = desk return idx end @@ -63,7 +92,7 @@ function Workspace:view(screen, desktop, page_idx) end -- the page to display on the target screen - page_idx = self.desktops[desktop]:show(screen, page_idx) + page_idx = desktop_show(self.desktops[desktop], screen, page_idx) local page_new = nil if page_idx then page_new = self.desktops[desktop].pages[page_idx] @@ -84,7 +113,7 @@ function Workspace:view(screen, desktop, page_idx) if screen_cur then local desk_prev = self.screen_state[screen_cur].desktop - old.page_idx = self.desktops[old.desk]:show(screen_cur, old.page_idx) + old.page_idx = desktop_show(self.desktops[old.desk], screen_cur, old.page_idx) self.screen_state[screen_cur] = { page = old.page_idx, desktop = old.desk } if desk_prev ~= old.desk then -- cgit v1.2.3