Elv13 / tyrannical

Dynamic tagging configuration system for awesomeWM
211 stars 33 forks source link

Tag not work with URxvt #70

Closed arkhan closed 5 years ago

arkhan commented 7 years ago

Hello, great work.

I have this:

Terminal file manager with URxvt:

fileman = terminal .. " -name Ranger -e ranger " .. datadir

Tag:

{name = "files",
   init = false,
   exclusive = true,
   screen = 1,
   class = {
     "Thunar", "Konqueror", "Dolphin",
     "ark", "Nautilus","emelfm",
     "URxvt:Ranger", "Dfm", "Dolphin:Move",
     "Dolphin:Copy",}
},

Rule:

{ rule = { class = "URxvt", instance = "Ranger" },
      callback = function (c)
        awful.client.property.set(c, "overwrite_class", "URxvt:Ranger")
      end
    },

but it does not work

Thanks

Elv13 commented 7 years ago

Hello, can you try to replace that function in tyrannical/init.lua (this is the fixed version)

--- Replace the default handler to take into account Tyrannical properties
function awful.rules.apply(c)
    local low_i = string.lower(c.instance or "N/A")
    local low_c = string.lower(get_class(c))

    local callbacks, props = {}, {}

    -- Add the rules properties
    for _, entry in ipairs(awful.rules.matching_rules(c, awful.rules.rules)) do
        awful.util.table.crush(props,entry.properties or {})

        if entry.callback then
            table.insert(callbacks, entry.callback)
        end
    end

    -- In case the class is overwriten
    low_c = props.overwrite_class or low_c

    -- Add Tyrannical properties
    local props_src = (c_rules.instance[low_i]
        or c_rules.class[low_c] or {}).properties
        or {}

    awful.util.table.crush(props,props_src)

    -- Add startup_id overridden properties
    if c.startup_id and awful.spawn.snid_buffer[c.startup_id] then
        local snprops, sncb = unpack(awful.spawn.snid_buffer[c.startup_id])

        -- The SNID tag(s) always have precedence over the rules one(s)
        if snprops.tag or snprops.tags or snprops.new_tag then
            props.tag, props.tags, props.new_tag, props.intrusive = nil, nil, nil, false
        end

        awful.util.table.crush(props,snprops)
        awful.util.table.merge(callbacks, sncb)
    end

    apply_properties(c,props, callbacks)
end
arkhan commented 7 years ago

Hello, I'm tried with:

{ rule = { class = "URxvt", name = "Ranger" },
      callback = function (c)
        awful.client.property.set(c, "overwrite_class", "URxvt:Ranger")
      end
    },

and

{ rule = { class = "URxvt", name = "Ranger" },
      callback = function (c)
        c.name = "URxvt:Ranger"
      end
    },

Hello, can you try to replace that function in tyrannical/init.lua (this is the fixed version)

--- Replace the default handler to take into account Tyrannical properties

function awful.rules.apply(c)
    local low_i = string.lower(c.instance or "N/A")
    local low_c = string.lower(get_class(c))

    local callbacks, props = {}, {}

    -- Add the rules properties
    for _, entry in ipairs(awful.rules.matching_rules(c, awful.rules.rules)) do
        awful.util.table.crush(props,entry.properties or {})

        if entry.callback then
            table.insert(callbacks, entry.callback)
        end
    end

    -- In case the class is overwriten
    low_c = props.overwrite_class or low_c

    -- Add Tyrannical properties
    local props_src = (c_rules.instance[low_i]
        or c_rules.class[low_c] or {}).properties
        or {}

    awful.util.table.crush(props,props_src)

    -- Add startup_id overridden properties
    if c.startup_id and awful.spawn.snid_buffer[c.startup_id] then
        local snprops, sncb = unpack(awful.spawn.snid_buffer[c.startup_id])

        -- The SNID tag(s) always have precedence over the rules one(s)
        if snprops.tag or snprops.tags or snprops.new_tag then
            props.tag, props.tags, props.new_tag, props.intrusive = nil, nil, nil, false
        end

        awful.util.table.crush(props,snprops)
        awful.util.table.merge(callbacks, sncb)
    end

    apply_properties(c,props, callbacks)
end

but dont work

arkhan commented 7 years ago

any news about this...?

warlock90000 commented 7 years ago

any news about this...?

++

Elv13 commented 7 years ago

I don't have much time for Awesome currently, if someone could take care of that for me it would be appreciated. The code still has unreadable parts, but I cleaned up it a bit since a last year. Also, there is https://github.com/awesomeWM/awesome/pull/1487 to upstream the code above, but it is stuck in a design decision deadlock.

freehaha commented 7 years ago

the problem seems to be the tag being requested before rules are applied in awful.rules.execute. Not sure what's the best way to work around it but we can do some magic in match_client when hints.reason="rules" or maybe preemptively apply the callback/specific property in apply_properties before awful.rules.execute like the following workaround:

in

local function apply_properties(c, props, callbacks)

replace

    awful.rules.execute(c, props, callbacks)

with

    -- preemptively apply the rule so we get a correct class in request::tag
    if props.overwrite_class then
        awful.client.property.set(c, "overwrite_class", props.overwrite_class)
    end
    awful.rules.execute(c, props, callbacks)

and for the rules, change from using callback to properties:

    {
        rule = { class = "URxvt", name = "dev" },
        callback = function(c)
            awful.client.property.set(c, "overwrite_class", "urxvt:dev")
        end
    },

to

    {
        rule = { class = "URxvt", name = "dev" },
        properties = {
            overwrite_class = "urxvt:dev"
        }
    },

note that if rxvt clients are set intrusive they will ignore the tag assignment and get tagged to whatever tag is available at the moment. (not sure if this is intended behavior)