From 603ff2ae14d72abe6456ddb038ea8fac0f8e5f91 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Mon, 29 Sep 2014 00:07:16 -0400 Subject: [PATCH] Add 'callback' client property --- README.md | 9 +++++++++ init.lua | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b50f854..36817b0 100644 --- a/README.md +++ b/README.md @@ -273,6 +273,7 @@ Then edit this section to fit your needs. | **no_autofocus** | Do not focus a new instance | boolean | | **tag** | Asign to a pre-existing tag object | tag/func/array | | **new_tag** | Do not focus a new instance | boolean or array | +| **callback** | A function returning an array or properties | function | *Need default rc.lua modifications in the "client.connect_signal('focus')" section @@ -407,6 +408,14 @@ use `Alt+Return` to launch it as an `intrusive` client. You can add more section to support more use case (such as `Shift+Return` to launch as `floating` as shown above) +#### Can I alter the client properties based on runtime criterias? + +Yes, everytime Tyrannical consider a client, it will call the `callback` function. +This function can return an array or properties that will have precedence over +any properties set by rules. The only limitation of this system is that the +callback function need to be synchronious. So long bash commands will cause +Awesome to block until the result is parsed. + #### What is Tyrannical license? Tyrannical is licensed under the [2 clause BSD](http://opensource.org/licenses/BSD-2-Clause) diff --git a/init.lua b/init.lua index bfba9e8..50aba07 100755 --- a/init.lua +++ b/init.lua @@ -95,7 +95,7 @@ end --Apply all properties local function apply_properties(c,override,normal) - local props,ret = awful.util.table.join(normal,override),nil + local props,ret = awful.util.table.join(normal,override,override.callback and override.callback(c) or (normal.callback and normal.callback(c)) or {}),nil --Set all 'c.something' properties, --TODO maybe eventually move to awful.rules.execute for k,_ in pairs(props) do if override[k] ~= nil then props[k] = override[k] else props[k] = normal[k] end @@ -113,11 +113,11 @@ local function apply_properties(c,override,normal) if props.slave == true or props.master == true then awful.client["set"..(props.slave and "slave" or "master")](c, true) end + --Check if the client should be added to an existing tag (or tags) if props.new_tag then ret = c:tags({awful.tag.add(type(props.new_tag)=="table" and props.new_tag.name or c.class,type(props.new_tag)=="table" and props.new_tag or {})}) elseif props.tag then ret = c:tags(type(props.tag) == "function" and props.tag(c) or (type(props.tag) == "table" and props.tag or { props.tag })) - --Add to the current tag if the client is intrusive, ignore exclusive elseif props.intrusive == true or (settings.force_odd_as_intrusive and c.type ~= "normal") then local tag = awful.tag.selected(c.screen) or awful.tag.viewonly(awful.tag.gettags(c.screen)[1]) or awful.tag.selected(c.screen) if tag then --Can be false if there is no tags