diff options
Diffstat (limited to '.config/awesome/charitable')
-rw-r--r-- | .config/awesome/charitable/.gitignore | 7 | ||||
-rw-r--r-- | .config/awesome/charitable/README.md | 124 | ||||
-rw-r--r-- | .config/awesome/charitable/init.lua | 160 |
3 files changed, 291 insertions, 0 deletions
diff --git a/.config/awesome/charitable/.gitignore b/.config/awesome/charitable/.gitignore new file mode 100644 index 0000000..edf2840 --- /dev/null +++ b/.config/awesome/charitable/.gitignore @@ -0,0 +1,7 @@ +.svn/* +*~ +*.bak +.vimrc* +*.swp +.idea +*.iml diff --git a/.config/awesome/charitable/README.md b/.config/awesome/charitable/README.md new file mode 100644 index 0000000..da4a924 --- /dev/null +++ b/.config/awesome/charitable/README.md @@ -0,0 +1,124 @@ +# Charitable + +Shared tags library for multiple monitors using AwesomeWM. +Sourced from https://github.com/frioux/charitable + +## Usage + +```lua +local charitable = require("charitable") + +-- Create tags and taglist +local taglist_buttons = gears.table.join( + awful.button({ }, 1, function(t) charitable.select_tag(t, awful.screen.focused()) end), + + awful.button({ }, 3, function(t) charitable.toggle_tag(t, awful.screen.focused()) end) +) + +local tags = charitable.create_tags( + { "1", "2", "3", "4", "5", "6", "7", "8", "9" }, + { + awful.layout.layouts[1], + awful.layout.layouts[1], + awful.layout.layouts[1], + awful.layout.layouts[1], + awful.layout.layouts[1], + awful.layout.layouts[1], + awful.layout.layouts[1], + awful.layout.layouts[1], + awful.layout.layouts[1], + } +) + +awful.screen.connect_for_each_screen(function(s) + -- Show an unselected tag when a screen is connected + for i = 1, #tags do + if not tags[i].selected then + tags[i].screen = s + tags[i]:view_only() + break + end + end + + s.mytaglist = awful.widget.taglist({ + screen = s, + filter = awful.widget.taglist.filter.all, + buttons = taglist_buttons, + source = function(screen, args) return tags end, + }) + + -- ... +end + +-- Keys setup +for i = 1, 9 do + globalkeys = gears.table.join(globalkeys, + -- View tag only. + awful.key({ modkey }, "#" .. i + 9, + function () charitable.select_tag(tags[i], awful.screen.focused()) end, + {description = "view tag #"..i, group = "tag"}), + -- Toggle tag display. + awful.key({ modkey, "Control" }, "#" .. i + 9, + function () charitable.toggle_tag(tags[i], awful.screen.focused()) end, + {description = "toggle tag #" .. i, group = "tag"}), + -- Move client to tag. + awful.key({ modkey, "Shift" }, "#" .. i + 9, + function () + if client.focus then + local tag = tags[i] + if tag then + client.focus:move_to_tag(tag) + end + end + end, + {description = "move focused client to tag #"..i, group = "tag"}), + -- Toggle tag on focused client. + awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9, + function () + if client.focus then + local tag = tags[i] + if tag then + client.focus:toggle_tag(tag) + end + end + end, + {description = "toggle focused client on tag #" .. i, group = "tag"}) + ) +end + +-- ensure that removing screens doesn't kill tags +tag.connect_signal("request::screen", function(t) + t.selected = false + for s in screen do + if s ~= t.screen then + t.screen = s + return + end + end +end) + +-- work around bugs in awesome 4.0 through 4.3+ +-- see https://github.com/awesomeWM/awesome/issues/2780 +awful.tag.history.restore = function() end +``` + +## Description + +Typical AwesomeWM configuration implies that tags are per screen. This library +allows AwesomeWM to instead have tags that are shared across all connected +screens. This is how XMonad works by default. + +## Quick Reference + + * `charitable.create_tags` replaces [`awful.tag.new`](https://awesomewm.org/doc/api/classes/tag.html#awful.tag.new) + * `charitable.select_tag` replaces [`t:view_only()`](https://awesomewm.org/doc/api/classes/tag.html#tag:view_only) + * `charitable.toggle_tag` replaces [`awful.tag.viewtoggle`](https://awesomewm.org/doc/api/classes/tag.html#awful.tag.viewtoggle) + * `charitable.tag_move` is new + * `charitable.swap_screen` is new + +## History + +This was [originally](https://github.com/lammermann) implemented by Benjamin +Kober, and later [forked and updated](https://github.com/XLegion/sharetags) by +Alexey Solodkiy. This version has been updated to support AwesomeWM 4.x, and +have a better name. diff --git a/.config/awesome/charitable/init.lua b/.config/awesome/charitable/init.lua new file mode 100644 index 0000000..8c0cc9b --- /dev/null +++ b/.config/awesome/charitable/init.lua @@ -0,0 +1,160 @@ +-- @module sharetags +-- functions to share tags on multiple screens +local sharetags = {} + +--{{{ Grab environment we need +local capi = { screen = screen, client = client } + +local pairs = pairs +local ipairs = ipairs +local tag = require("awful.tag") +local awful = require("awful") + +--}}} + + +--{{{ Functions + +--{{{ create_tags: create a table of tags and bind them to screens +-- @param names : list to label the tags +-- @param layouts : list of layouts for the tags +-- @return table of tag objects +function sharetags.create_tags(names, layouts) + local tags = {} + local count = #names + if capi.screen.count() >= #names then + count = capi.screen.count() + 1 + end + + for tagnumber = 1, count do + tags[tagnumber] = tag.add(names[tagnumber], {}) + tags[tagnumber].number = tagnumber + + awful.layout.set(layouts[tagnumber], tags[tagnumber]) + end + return tags +end +--}}} + +--{{{ sharetags.tag_move: move a tag to a screen +-- @param t : the tag object to move +-- @param screen_target : the screen object to move to +function sharetags.tag_move(t, target_screen) + local ts = t or tag.selected() + + if not target_screen then return end + + local current_screen = ts.screen + + if current_screen and target_screen ~= current_screen then + -- switch for tag + local mynumber = ts.number + + -- sort tags + local index = #target_screen.tags + 1 + for i, screen_tag in pairs(target_screen.tags) do + local number = screen_tag.number + if number ~= nil and mynumber < number then + index = i + break + end + end + + -- save curren_screen tags + local selected_tags = current_screen.selected_tags + + ts.screen = target_screen + ts.index = index + + -- restore curren_screen tag + tag.viewmore(selected_tags, current_screen) + + + -- switch for all clients on tag + if #ts:clients() > 0 then + for _, c in ipairs(ts:clients()) do + if not c.sticky then + c.screen = target_screen + c:tags({ ts }) + + -- Fix maximized client if display sizes not equal + local is_maximized = c.maximized + if is_maximized then + c.maximized = false + c.maximized = true + end + else + awful.client.toggletag(ts, c) + end + end + end + end +end +--}}} + + +-- Open tag on screen +function sharetags.select_tag(t, target_screen) + local prev_focus = capi.client.focus; + local tag_screen = t.screen + local is_tag_select = t.selected; + local is_tag_moved = target_screen ~= tag_screen + + + if t.selected and target_screen ~= tag_screen and #tag_screen.selected_tags == 1 then + sharetags.swap_screen(tag_screen, target_screen) + else + sharetags.tag_move(t, target_screen) + t:view_only() + end + + + -- If there was a moving tag then the focus on the window is lost. Checking + -- if this is the same tag and thus restore focus on the window + if is_tag_moved and is_tag_select and #t:clients() > 0 and prev_focus then + capi.client.focus = prev_focus + end +end + +-- Toggle tag on screen +function sharetags.toggle_tag(t, screen) + if t.screen ~= screen then + sharetags.tag_move(t, screen) + if not t.selected then + tag.viewtoggle(t) + end + else + tag.viewtoggle(t) + end +end + +-- Swap all selected tags between two screens +function sharetags.swap_screen(s1, s2) + if #s1.selected_tags ~= 1 or #s2.selected_tags ~= 1 then + print("can't swap multiple selected tags yet") + end + + local t1 = s1.selected_tag + local t2 = s2.selected_tag + + -- hide both tags in scratch space + t1:swap(t2) + + -- Set selected in both screens to the correct count + if #s1.selected_tags ~= 1 then + for _, t in ipairs(s1.selected_tags) do + t.selected = false + end + end + + if #s2.selected_tags ~= 1 then + for _, t in ipairs(s2.selected_tags) do + t.selected = false + end + end + + t1.selected = true + t2.selected = true +end + +return sharetags |