summaryrefslogtreecommitdiff
path: root/pager.lua
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2017-01-26 12:25:52 +0100
committerAnton Khirnov <anton@khirnov.net>2017-01-26 12:25:52 +0100
commit9b322660ee6b7640af24def50a7fb8615a8ab126 (patch)
treea3064adc789a0ed91149432a15b86c66d7967c35 /pager.lua
parente8bb1f4a1844f07fc2f6973f2e7b400f2ddf2f3d (diff)
Basic support for desktops/pages.
Diffstat (limited to 'pager.lua')
-rw-r--r--pager.lua147
1 files changed, 119 insertions, 28 deletions
diff --git a/pager.lua b/pager.lua
index 867b09b..1cef725 100644
--- a/pager.lua
+++ b/pager.lua
@@ -1,47 +1,138 @@
local M = {}
-local wibox = require("wibox")
+local awful = require("awful")
+local beautiful = require("beautiful")
+local wibox = require("wibox")
-local Pager = {}
+local Page = {}
-local function pager_fit(pager, width, height)
- return width, width * #pager.desktop.pages
+function Page:set_active(active)
+ local border_color = nil
+ if active then
+ border_color = beautiful.border_focus or '#ffffff'
+ else
+ border_color = beautiful.border_normal or '#000000'
+ end
+ self.border:set_color(border_color)
end
-local function pager_draw(pager, wibox, cr, width, height)
- if pager.desktop == nil then
- return
+function Page:update()
+ local font = beautiful.small_text_font or "sans 7"
+
+ self.client_container:reset()
+ for i, client in pairs(self.tag:clients()) do
+ local text = client.name
+
+ local bg_normal = beautiful.bg_normal or "#000000"
+ local fg_normal = beautiful.fg_normal or "#ffffff"
+ local bg_focus = beautiful.bg_focus or "#ffffff"
+ local fg_focus = beautiful.fg_focus or "#000000"
+
+ local tb = wibox.widget.textbox(text, true)
+ local bg = wibox.widget.background(tb, bg)
+
+ tb:set_font(font)
+
+ client:connect_signal("property::name", function() tb:set_text(client.name) end)
+ client:connect_signal("focus",
+ function(c)
+ if c.screen == self.pager.init_data.screen then
+ bg:set_bg(bg_focus)
+ bg:set_fg(fg_focus)
+ end
+ end)
+ client:connect_signal("unfocus",
+ function(c)
+ if c.screen == self.pager.init_data.screen then
+ bg:set_bg(bg_normal)
+ bg:set_fg(fg_normal)
+ end
+ end)
+
+ self.client_container:add(bg)
end
+end
- local nb_pages = #pager.desktop.pages
- local page_height = height / nb_pages
+function Page:new(tag, index, width, height, pager)
+ local ret = setmetatable({}, self)
+ self.__index = self
- for i = 1, nb_pages do
- local page = pager.desktop.pages[i]
- local draw_h_start = (i - 1) * page_height
-
- for j, client in pairs(page:clients()) do
- local text = client.name
- local extents = cr:text_extents(text)
- cr:move_to(0, draw_h_start)
- cr:show_text(text)
- draw_h_start = draw_h_start + extents.height
+ local client_container = wibox.layout.flex.vertical()
+
+ local border_width = beautiful.border_width or 1
+ local margin = wibox.layout.margin(client_container)
+ margin:set_top(border_width)
+ margin:set_bottom(border_width)
+
+ ret.widget = wibox.layout.constraint(margin, 'exact', width, height)
+
+ ret.client_container = client_container
+ ret.border = margin
+ ret.tag = tag
+ ret.pager = pager
+
+ tag:connect_signal('tagged', function (c) ret:update() end)
+ tag:connect_signal('untagged', function (c) ret:update() end)
+
+ ret:set_active(false)
+ ret:update()
+
+ return ret
+end
+
+local function pager_set_active(self, screen, page_idx)
+ if self.init_data.screen == screen then
+ if self.active_page then
+ self.active_page:set_active(false)
end
+ self.pages[page_idx]:set_active(true)
+ self.active_page = self.pages[page_idx]
end
- cr:set_line_width(3)
- cr:stroke()
end
-local function pager_set_desktop(pager, desktop)
- pager.desktop = desktop
- pager:emit_signal("widget::updated")
+local function pager_set_desktop(self, desktop)
+ init_data = self.init_data
+
+ print("pager " .. init_data.screen .. " set desktop")
+
+ self:reset()
+
+ self.init_data = init_data
+ self.set_desktop = pager_set_desktop
+
+ self.active_page = nil
+ self.pages = {}
+
+ self.desktop = desktop
+
+ local nb_pages = #self.desktop.pages
+ local page_height = self.init_data.height / nb_pages
+
+ local title = wibox.widget.textbox(desktop.name, false)
+ title:set_align("center")
+ local title_bg = beautiful.bg_focus or "#ffffff"
+ local title_fg = beautiful.fg_focus or "#000000"
+ local title_container = wibox.widget.background(title, title_bg)
+ title_container:set_fg(title_fg)
+ self:add(title_container)
+
+ for i = 1, nb_pages do
+ local page = self.desktop.pages[i]
+ self.pages[i] = Page:new(page, i, self.init_data.width, page_height, self)
+ self:add(self.pages[i].widget)
+ end
+
+ self.desktop:connect_signal("page:view",
+ function(desktop, s, page_idx)
+ pager_set_active(self, s, page_idx) end)
end
-function Pager:new()
- local pager = wibox.widget.base.make_widget()
+local Pager = {}
+
+function Pager:new(screen, width, height)
+ local pager = wibox.layout.fixed.vertical()
- pager.fit = pager_fit
- pager.draw = pager_draw
+ pager.init_data = { screen = screen, width = width, height = height }
pager.set_desktop = pager_set_desktop
return pager