[awful/tabulous] Tagging to marking, add tabulous keybindings

Rename awful tagging to marking clients, create ismarked, togglemarked
and unmark, use userhooks for marked and unmarked, add tabulous
keybindings to the default config.

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Lucas de Vries 2008-06-11 10:35:54 +02:00 committed by Julien Danjou
parent eafb88f232
commit 76657e590c
2 changed files with 143 additions and 53 deletions

View File

@ -2,6 +2,10 @@
-- Include awesome library, with lots of useful function! -- Include awesome library, with lots of useful function!
require("awful") require("awful")
require("tabulous")
-- Uncomment this to activate autotabbing
-- tabulous.autotab_start()
-- {{{ Colors and fonts -- {{{ Colors and fonts
awesome.font_set("sans 8") awesome.font_set("sans 8")
@ -175,15 +179,51 @@ keybinding.new({ modkey, "Shift" }, "space", function () awful.layout.inc(layout
-- Menu -- Menu
keybinding.new({ modkey }, "F1", function () awful.menu("Run: ", mymenubox, awful.spawn) end):add() keybinding.new({ modkey }, "F1", function () awful.menu("Run: ", mymenubox, awful.spawn) end):add()
--- Tabulous, tab manipulation
keybinding.new({ modkey, "Control" }, "y", function ()
local tabbedview = tabulous.tabindex_get()
if tabbedview == nil then
tabbedview = tabulous.tab_create()
end
tabulous.tab(tabbedview, awful.client.next(1))
end):add()
keybinding.new({ modkey, "Shift" }, "y", tabulous.untab):add()
keybinding.new({ modkey }, "y", function ()
local tabbedview = tabulous.tabindex_get()
if tabbedview ~= nil then
local n = tabulous.next(tabbedview)
tabulous.display(tabbedview, n)
end
end):add()
-- Client awful tagging: this is useful to tag some clients and then do stuff like move to tag on them -- Client awful tagging: this is useful to tag some clients and then do stuff like move to tag on them
awful.client.ontag(function (c) c:border_set({ color = "red" }) end) keybinding.new({ modkey }, "t", awful.client.togglemarked):add()
keybinding.new({ modkey }, "t", awful.client.tag):add() keybinding.new({ modkey, 'Shift' }, "t", function ()
local tabbedview = tabulous.tabindex_get()
local clients = awful.client.getmarked()
if tabbedview == nil then
tabbedview = tabulous.tab_create(clients[1])
table.remove(clients, 1)
end
for k,c in pairs(clients) do
tabulous.tab(tabbedview, c)
end
end):add()
for i = 1, keynumber do for i = 1, keynumber do
keybinding.new({ modkey, "Shift" }, "F" .. i, keybinding.new({ modkey, "Shift" }, "F" .. i,
function () function ()
local screen = mouse.screen_get() local screen = mouse.screen_get()
if tags[screen][i] then if tags[screen][i] then
for c, v in pairs(awful.client.gettagged()) do for k, c in pairs(awful.client.getmarked()) do
awful.client.movetotag(tags[screen][i], c) awful.client.movetotag(tags[screen][i], c)
end end
end end
@ -194,12 +234,26 @@ end
-- {{{ Hooks -- {{{ Hooks
-- Hook function to execute when focusing a client. -- Hook function to execute when focusing a client.
function hook_focus(c) function hook_focus(c)
c:border_set({ width = 1, color = "white" }) if not awful.client.ismarked(c) then
c:border_set({ width = 1, color = "white" })
end
end end
-- Hook function to execute when unfocusing a client. -- Hook function to execute when unfocusing a client.
function hook_unfocus(c) function hook_unfocus(c)
c:border_set({ width = 1, color = "black" }) if not awful.client.ismarked(c) then
c:border_set({ width = 1, color = "black" })
end
end
-- Hook function to execute when marking a client
function hook_marked(c)
c:border_set({ width = 1, color = "red" })
end
-- Hook function to execute when unmarking a client
function hook_unmarked(c)
c:border_set({ width = 1, color = "white" })
end end
-- Hook function to exeucte when the mouse is over a client. -- Hook function to exeucte when the mouse is over a client.
@ -239,6 +293,8 @@ end
-- Set up some hooks -- Set up some hooks
awful.hooks.focus(hook_focus) awful.hooks.focus(hook_focus)
awful.hooks.unfocus(hook_unfocus) awful.hooks.unfocus(hook_unfocus)
awful.hooks.marked(hook_marked)
awful.hooks.unmarked(hook_unmarked)
awful.hooks.manage(hook_manage) awful.hooks.manage(hook_manage)
awful.hooks.mouseover(hook_mouseover) awful.hooks.mouseover(hook_mouseover)
awful.hooks.arrange(hook_arrange) awful.hooks.arrange(hook_arrange)

130
awful.lua
View File

@ -31,6 +31,26 @@ local keygrabber = keygrabber
-- Reset env -- Reset env
setfenv(1, P) setfenv(1, P)
-- Hook functions, wrappers around awesome's hooks. functions so we
-- can easily add multiple functions per hook.
P.hooks = {}
P.myhooks = {}
-- Create a new userhook (for external libs)
local function userhook_create(name)
P.myhooks[name] = {}
P.hooks[name] = function (f)
table.insert(P.myhooks[name], {callback = f})
end
end
-- Call a created userhook (for external libs
local function userhook_call(name, args)
for i,o in pairs(P.myhooks[name]) do
P.myhooks[name][i]['callback'](unpack(args))
end
end
-- Function to the good value in table, cycling -- Function to the good value in table, cycling
local function array_boundandcycle(t, i) local function array_boundandcycle(t, i)
if i > #t then if i > #t then
@ -268,42 +288,75 @@ local function layout_get(screen)
end end
end end
-- Just set a awful tag to a client to move it later. -- Just set an awful mark to a client to move it later.
local awfultags = {} local awfulmarked = {}
local ontag_callback = nil userhook_create('marked')
local onuntag_callback = nil userhook_create('unmarked')
local function client_ontag (f) -- Mark a client
ontag_callback = f local function client_mark (c)
end
local function client_onuntag (f)
onuntag_callback = f
end
local function client_tag (c)
local cl = c or client.focus_get() local cl = c or client.focus_get()
if cl then if cl then
for k, v in pairs(awfultags) do for k, v in pairs(awfulmarked) do
if cl == v then if cl == v then
return return false
end end
end end
awfultags[cl] = true
table.insert(awfulmarked, cl)
-- Call callback -- Call callback
if ontag_callback then ontag_callback(cl) end userhook_call('marked', {cl})
return true
end end
end end
-- Return the tagged client and empty the table -- Unmark a client
local function client_gettagged () local function client_unmark(c)
if onuntag_callback then local cl = c or client.focus_get()
for k, v in pairs(awfultags) do
onuntag_callback(k) for k, v in pairs(awfulmarked) do
if cl == v then
table.remove(awfulmarked, k)
userhook_call('unmarked', {cl})
return true
end end
end end
t = awfultags
awfultags = {} return false
end
-- Check if marked
local function client_ismarked(c)
local cl = c or client.focus_get()
if cl then
for k, v in pairs(awfulmarked) do
if cl == v then
return true
end
end
return false
end
end
-- Toggle marked
local function client_togglemarked(c)
local cl = c or client.focus_get()
if not client_mark(c) then
client_unmark(c)
end
end
-- Return the marked clients and empty the table
local function client_getmarked ()
for k, v in pairs(awfulmarked) do
userhook_call('unmarked', {v})
end
t = awfulmarked
awfulmarked = {}
return t return t
end end
@ -336,26 +389,6 @@ local function layout_set(layout)
end end
end end
-- Hook functions, wrappers around awesome's hooks. functions so we
-- can easily add multiple functions per hook.
P.hooks = {}
P.myhooks = {}
-- Create a new userhook (for external libs)
local function userhook_create(name)
P.myhooks[name] = {}
P.hooks[name] = function (f)
table.insert(P.myhooks[name], {callback = f})
end
end
-- Call a created userhook (for external libs
local function userhook_call(name, args)
for i,o in pairs(P.myhooks[name]) do
P.myhooks[name][i]['callback'](unpack(args))
end
end
P.hooks['userhook_create'] = userhook_create P.hooks['userhook_create'] = userhook_create
P.hooks['userhook_call'] = userhook_call P.hooks['userhook_call'] = userhook_call
@ -468,10 +501,11 @@ P.client =
togglefloating = client_togglefloating; togglefloating = client_togglefloating;
moveresize = client_moveresize; moveresize = client_moveresize;
movetoscreen = client_movetoscreen; movetoscreen = client_movetoscreen;
tag = client_tag; mark = client_mark;
gettagged = client_gettagged; unmark = client_unmark;
ontag = client_ontag; ismarked = client_ismarked;
onuntag = client_onuntag; togglemarked = client_togglemarked;
getmarked = client_getmarked;
} }
P.screen = P.screen =
{ {