Updated to work with awesome v4.0

This commit is contained in:
Drauthius 2017-02-25 16:59:55 +01:00
parent 954b24addf
commit 54f5929fc5
4 changed files with 145 additions and 155 deletions

View File

@ -4,7 +4,7 @@ awesome-sharedtags
A simple implementation for creating tags shared on multiple screens for
[awesome window manager](http://awesome.naquadah.org/).
This branch of the library is intended to work with *awesome* version 3.5 (and
This branch of the library is intended to work with *awesome* version 4.0 (and
all minor versions), but there are other branches with support for other
versions.
@ -20,7 +20,7 @@ Installation
1. Clone or download a zip of the repository, and put the `sharedtags`
directory somewhere where you can easily include it, for example in the same
directory as your `rc.lua` file.
directory as your `rc.lua` file, generally located in `~/.config/awesome/`.
2. Modify your `rc.lua` file. A [patch](rc.lua.patch) against the default
configuration is included in the repository for easy comparison, but keep
reading for a textual description.
@ -30,18 +30,33 @@ Installation
local sharedtags = require("sharedtags")
```
2. Create the tags using the `sharedtags()` method, instead of the original
ones created with `awful.tag()`.
ones created with `awful.tag()`. They should be created at the file level,
i.e. outside of any function.
```lua
local tags = sharedtags(
{ name = "main", layout = layouts[2] },
{ name = "www", layout = awful.layout.suit.max },
{ name = "chat", screen = 2, layout = layouts[1] },
{ layout = layouts[2] },
{ screen = 2, layout = layouts[2] }
)
local tags = sharedtags({
{ name = "main", layout = awful.layout.layouts[2] },
{ name = "www", layout = awful.layout.layouts[10] },
{ name = "game", layout = awful.layout.layouts[1] },
{ name = "misc", layout = awful.layout.layouts[2] },
{ name = "chat", screen = 2, layout = awful.layout.layouts[2] },
{ layout = awful.layout.layouts[2] },
{ screen = 2, layout = awful.layout.layouts[2] }
})
```
3. The code for handling tags and clients needs to be changed to use the
3. Remove or uncomment the code which creates the tags when a screen is
connected, in the `connect_for_each_screen` callback.
```lua
awful.screen.connect_for_each_screen(function(s)
-- Each screen has its own tag table.
--awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, s, awful.layout.layouts[1])
-- Here is a good place to add tags to a newly connected screen, if desired:
--sharedtags.viewonly(tags[4], s)
end)
```
4. The code for handling tags and clients needs to be changed to use the
library.
```lua
@ -50,43 +65,25 @@ Installation
-- View tag only.
awful.key({ modkey }, "#" .. i + 9,
function ()
local screen = awful.screen.focused()
local tag = tags[i]
if tag then
sharedtags.viewonly(tag)
sharedtags.viewonly(tag, screen)
end
end),
-- Toggle tag.
awful.key({ modkey, "Control" }, "#" .. i + 9,
function ()
local screen = awful.screen.focused()
local tag = tags[i]
if tag then
sharedtags.viewtoggle(tag)
end
end),
-- Move client to tag.
awful.key({ modkey, "Shift" }, "#" .. i + 9,
function ()
if client.focus then
local tag = tags[i]
if tag then
awful.client.movetotag(tag)
end
end
end),
-- Toggle tag.
awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
function ()
if client.focus then
local tag = tags[i]
if tag then
awful.client.toggletag(tag)
end
sharedtags.viewtoggle(tag, screen)
end
end))
end
```
4. Lastly, since the tag list is now a one-dimensional array, any references
to the `tags` array needs to be changed, for example in the rules section.
5. Lastly, any rules referencing the screen and tag should use the newly
created `tags` array instead.
```lua
awful.rules.rules = {
@ -100,9 +97,29 @@ Installation
Notes
-----
Because of constraints in the X server, *awesome* does not allow
toggling clients on tags allocated to other screens. Having a client on
multiple tags and moving one of the tags will cause the client to move as well.
1. There is a bug in [awesome v4.0](https://github.com/awesomeWM/awesome/pull/1600)
which can cause all tags to be deselected when moving a tag to another
screen. The following patch can be used to fix the problem.
```diff
diff --git a/lib/awful/tag.lua b/lib/awful/tag.lua
index 66bd0c1..b481f42 100644
--- a/lib/awful/tag.lua
+++ b/lib/awful/tag.lua
@@ -475,7 +475,7 @@ end
function tag.object.set_screen(t, s)
s = get_screen(s or ascreen.focused())
- local sel = tag.selected
+ local sel = t.selected
local old_screen = get_screen(tag.getproperty(t, "screen"))
if s == old_screen then return end
```
The file is located under `/usr/share/awesome/lib/awful/tag.lua` on my
system.
2. Because of constraints in the X server, *awesome* does not allow
toggling clients on tags allocated to other screens. Having a client on
multiple tags and moving one of the tags will cause the client to move as well.
API
---

View File

@ -60,15 +60,15 @@
<td class="summary">Create new tag objects.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#movetag">movetag (tag[, screen=capi.mouse.screen])</a></td>
<td class="name" nowrap><a href="#movetag">movetag (tag[, screen=awful.screen.focused()])</a></td>
<td class="summary">Move the specified tag to a new screen, if necessary.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#viewonly">viewonly (tag[, screen=capi.mouse.screen])</a></td>
<td class="name" nowrap><a href="#viewonly">viewonly (tag[, screen=awful.screen.focused()])</a></td>
<td class="summary">View the specified tag on the specified screen.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#viewtoggle">viewtoggle (tag[, screen=capi.mouse.screen])</a></td>
<td class="name" nowrap><a href="#viewtoggle">viewtoggle (tag[, screen=awful.screen.focused()])</a></td>
<td class="summary">Toggle the specified tag on the specified screen.</td>
</tr>
</table>
@ -122,13 +122,13 @@
</span> { name = <span class="string">"www"</span> },
<span class="comment">-- Third tag is named "3" on screen 1 with the floating layout.
</span> {})
-- tags[<span class="number">2</span>] <span class="keyword">and</span> tags[<span class="string">"www"</span>] both refer to the same tag.</pre>
-- tags[<span class="number">2</span>] <span class="keyword">and</span> tags[<span class="string">"www"</span>] both refer to the same tag.</pre>
</ul>
</dd>
<dt>
<a name = "movetag"></a>
<strong>movetag (tag[, screen=capi.mouse.screen])</strong>
<strong>movetag (tag[, screen=awful.screen.focused()])</strong>
</dt>
<dd>
Move the specified tag to a new screen, if necessary.
@ -142,7 +142,7 @@
<li><span class="parameter">screen</span>
<span class="types"><span class="type">number</span></span>
The screen to move the tag to.
(<em>default</em> capi.mouse.screen)
(<em>default</em> awful.screen.focused())
</li>
</ul>
@ -159,7 +159,7 @@
</dd>
<dt>
<a name = "viewonly"></a>
<strong>viewonly (tag[, screen=capi.mouse.screen])</strong>
<strong>viewonly (tag[, screen=awful.screen.focused()])</strong>
</dt>
<dd>
View the specified tag on the specified screen.
@ -173,7 +173,7 @@
<li><span class="parameter">screen</span>
<span class="types"><span class="type">number</span></span>
The screen to view the tag on.
(<em>default</em> capi.mouse.screen)
(<em>default</em> awful.screen.focused())
</li>
</ul>
@ -184,7 +184,7 @@
</dd>
<dt>
<a name = "viewtoggle"></a>
<strong>viewtoggle (tag[, screen=capi.mouse.screen])</strong>
<strong>viewtoggle (tag[, screen=awful.screen.focused()])</strong>
</dt>
<dd>
Toggle the specified tag on the specified screen.
@ -200,7 +200,7 @@
<li><span class="parameter">screen</span>
<span class="types"><span class="type">number</span></span>
The screen to toggle the tag on.
(<em>default</em> capi.mouse.screen)
(<em>default</em> awful.screen.focused())
</li>
</ul>
@ -216,7 +216,7 @@
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2016-01-09 21:09:20 </i>
<i style="float:right;">Last updated 2017-02-19 20:59:33 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>

View File

@ -6,20 +6,15 @@
-- Grab environment we need
local awful = require("awful")
local capi = {
tag = tag,
screen = screen,
mouse = mouse
}
local sharedtags = {
_VERSION = "sharedtags v1.0.0",
_DESCRIPTION = "Share tags for awesome window manager",
_VERSION = "sharedtags v1.0.0 for v4.0",
_DESCRIPTION = "Share tags for awesome window manager v4.0",
_URL = "https://github.com/Drauthius/awesome-sharedtags",
_LICENSE = [[
MIT LICENSE
Copyright (c) 2016 Albert Diserholt
Copyright (c) 2017 Albert Diserholt
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@ -65,7 +60,7 @@ function sharedtags.new(def)
for i,t in ipairs(def) do
tags[i] = awful.tag.add(t.name or i, {
screen = math.min(capi.screen.count(), t.screen or 1),
screen = t.screen or awful.screen.primary,
layout = t.layout,
sharedtagindex = i
})
@ -76,8 +71,8 @@ function sharedtags.new(def)
end
-- If no tag is selected for this screen, then select this one.
if not awful.tag.selected(awful.tag.getscreen(tags[i])) then
awful.tag.viewonly(tags[i]) -- Updates the history as well.
if not tags[i].screen.selected_tag then
tags[i]:view_only() -- Updates the history as well.
end
end
@ -86,50 +81,40 @@ end
--- Move the specified tag to a new screen, if necessary.
-- @param tag The tag to move.
-- @tparam[opt=capi.mouse.screen] number screen The screen to move the tag to.
-- @tparam[opt=awful.screen.focused()] number screen The screen to move the tag to.
-- @treturn bool Whether the tag was moved.
function sharedtags.movetag(tag, screen)
screen = screen or capi.mouse.screen
local oldscreen = awful.tag.getscreen(tag)
screen = screen or awful.screen.focused()
local oldscreen = tag.screen
-- If the specified tag is allocated to another screen, we need to move it.
if oldscreen ~= screen then
local oldsel = awful.tag.selected(oldscreen)
-- This works around a bug in the taglist module. It only receives
-- signals for when a tag or client changes something. Moving a tag
-- with no clients doesn't trigger a signal, and can thus leave the
-- taglist outdated. The work around is to hide the tag prior to the
-- move, and then restore its hidden status.
local hide = awful.tag.getproperty(tag, "hide")
awful.tag.setproperty(tag, "hide", true)
awful.tag.setscreen(tag, screen)
awful.tag.setproperty(tag, "hide", hide)
local oldsel = oldscreen.selected_tag
tag.screen = screen
if oldsel == tag then
-- The tag has been moved away. In most cases the tag history
-- function will find the best match, but if we really want we can
-- try to find a fallback tag as well.
if not awful.tag.selected(oldscreen) then
if not oldscreen.selected_tag then
local newtag = awful.tag.find_fallback(oldscreen)
if newtag then
awful.tag.viewonly(newtag)
newtag:view_only()
end
end
else
-- A bit of a weird one. Moving a previously selected tag
-- deselects the current tag, probably because the history is
-- restored to the first entry. Restoring it to the previous entry
-- seems to work well enough.
awful.tag.history.restore(oldscreen, "previous")
--else
-- NOTE: A bug in awesome 4.0 is causing all tags to be deselected
-- here. A shame, but I haven't found a nice way to work around it
-- except by fixing the bug (history seems to be in a weird state).
end
-- Also sort the tag in the taglist, by reapplying the index. This is just a nicety.
for _,screen in ipairs({ screen, oldscreen }) do
for _,t in ipairs(awful.tag.gettags(screen)) do
awful.tag.setproperty(t, "index", awful.tag.getproperty(t, "sharedtagindex"))
local unpack = unpack or table.unpack
for _,s in ipairs({ screen, oldscreen }) do
local tags = { unpack(s.tags) } -- Copy
table.sort(tags, function(a, b) return a.sharedtagindex < b.sharedtagindex end)
for i,t in ipairs(tags) do
t.index = i
end
end
@ -141,35 +126,33 @@ end
--- View the specified tag on the specified screen.
-- @param tag The only tag to view.
-- @tparam[opt=capi.mouse.screen] number screen The screen to view the tag on.
-- @tparam[opt=awful.screen.focused()] number screen The screen to view the tag on.
function sharedtags.viewonly(tag, screen)
sharedtags.movetag(tag, screen)
awful.tag.viewonly(tag)
tag:view_only()
end
--- Toggle the specified tag on the specified screen.
-- The tag will be selected if the screen changes, and toggled if it does not
-- change the screen.
-- @param tag The tag to toggle.
-- @tparam[opt=capi.mouse.screen] number screen The screen to toggle the tag on.
-- @tparam[opt=awful.screen.focused()] number screen The screen to toggle the tag on.
function sharedtags.viewtoggle(tag, screen)
local oldscreen = awful.tag.getscreen(tag)
local oldscreen = tag.screen
if sharedtags.movetag(tag, screen) then
-- Always mark the tag selected if the screen moved. Just feels a lot
-- Always mark the tag selected if the screen changed. Just feels a lot
-- more natural.
tag.selected = true
-- Update the history on the old and new screens.
capi.screen[oldscreen]:emit_signal("tag::history::update")
capi.screen[awful.tag.getscreen(tag)]:emit_signal("tag::history::update")
oldscreen:emit_signal("tag::history::update")
tag.screen:emit_signal("tag::history::update")
else
-- Only toggle the tag unless the screen moved.
awful.tag.viewtoggle(tag)
end
end
capi.tag.add_signal("property::sharedtagindex")
return setmetatable(sharedtags, { __call = function(...) return sharedtags.new(select(2, ...)) end })
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -1,95 +1,85 @@
This patch adds the necessary changes to create and manage tags shareable on
all screens when using the awesome window manager.
all screens when using the awesome window manager version 4.0.
The library and all relevant documentation can be found at
https://github.com/Drauthius/awesome-sharedtags
--- orig/rc.lua 2016-01-01 13:45:26.000000000 +0100
+++ sharedtags/rc.lua 2016-01-05 20:09:21.428836239 +0100
@@ -36,6 +36,11 @@
@@ -36,6 +36,10 @@
end
-- }}}
+-- {{{ Local extensions
+local sharedtags = require("sharedtags")
+-- }}}
+
+
-- {{{ Variable definitions
-- Themes define colours, icons, font and wallpapers.
beautiful.init("/usr/share/awesome/themes/default/theme.lua")
@@ -79,12 +84,16 @@
beautiful.init(awful.util.get_themes_dir() .. "default/theme.lua")
@@ -88,6 +94,18 @@
end
-- }}}
-- {{{ Tags
--- Define a tag table which hold all screen tags.
-tags = {}
-for s = 1, screen.count() do
- -- Each screen has its own tag table.
- tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, layouts[1])
-end
+-- Define a tag table shared among all screens.
+-- {{{ Tags
+local tags = sharedtags({
+ { name = "main", layout = layouts[2] },
+ { name = "www", layout = layouts[10] },
+ { name = "chat", screen = 2, layout = layouts[1] },
+ { name = "game", layout = layouts[1] },
+ { layout = layouts[2] },
+ { layout = layouts[2] },
+ { screen = 2, layout = layouts[2] }
+ { name = "main", layout = awful.layout.layouts[2] },
+ { name = "www", layout = awful.layout.layouts[10] },
+ { name = "game", layout = awful.layout.layouts[1] },
+ { name = "misc", layout = awful.layout.layouts[2] },
+ { name = "chat", screen = 2, layout = awful.layout.layouts[2] },
+ { layout = awful.layout.layouts[2] },
+ { screen = 2, layout = awful.layout.layouts[2] }
+})
-- }}}
+-- }}}
+
-- {{{ Menu
@@ -302,26 +311,24 @@
-- View tag only.
-- Create a launcher widget and a main menu
myawesomemenu = {
@@ -179,8 +197,9 @@
-- Wallpaper
set_wallpaper(s)
- -- Each screen has its own tag table.
- awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, s, awful.layout.layouts[1])
+ -- Assign tags to the newly connected screen here,
+ -- if desired:
+ --sharedtags.viewonly(tags[4], s)
-- Create a promptbox for each screen
s.mypromptbox = awful.widget.prompt()
@@ -372,9 +402,9 @@
awful.key({ modkey }, "#" .. i + 9,
function ()
- local screen = mouse.screen
- local tag = awful.tag.gettags(screen)[i]
local screen = awful.screen.focused()
- local tag = screen.tags[i]
+ local tag = tags[i]
if tag then
- awful.tag.viewonly(tag)
+ sharedtags.viewonly(tag)
- tag:view_only()
+ sharedtags.viewonly(tag, screen)
end
end),
-- Toggle tag.
end,
{description = "view tag #"..i, group = "tag"}),
@@ -382,9 +412,9 @@
awful.key({ modkey, "Control" }, "#" .. i + 9,
function ()
- local screen = mouse.screen
- local tag = awful.tag.gettags(screen)[i]
local screen = awful.screen.focused()
- local tag = screen.tags[i]
+ local tag = tags[i]
if tag then
- awful.tag.viewtoggle(tag)
+ sharedtags.viewtoggle(tag)
+ sharedtags.viewtoggle(tag, screen)
end
end),
-- Move client to tag.
awful.key({ modkey, "Shift" }, "#" .. i + 9,
function ()
if client.focus then
- local tag = awful.tag.gettags(client.focus.screen)[i]
+ local tag = tags[i]
if tag then
awful.client.movetotag(tag)
end
@@ -331,7 +338,7 @@
awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
function ()
if client.focus then
- local tag = awful.tag.gettags(client.focus.screen)[i]
+ local tag = tags[i]
if tag then
awful.client.toggletag(tag)
end
@@ -365,9 +372,9 @@
properties = { floating = true } },
{ rule = { class = "gimp" },
properties = { floating = true } },
- -- Set Firefox to always map on tags number 2 of screen 1.
+ -- Set Firefox to always map on tag number 2.
end,
{description = "toggle tag #" .. i, group = "tag"}),
@@ -469,9 +469,9 @@
}, properties = { titlebars_enabled = true }
},
- -- Set Firefox to always map on the tag named "2" on screen 1.
+ -- Set Firefox to always map on the tag named "2".
-- { rule = { class = "Firefox" },
- -- properties = { tag = tags[1][2] } },
- -- properties = { screen = 1, tag = "2" } },
+ -- properties = { tag = tags[2] } }, -- tag = tags["www"] works as well
}
-- }}}