Elv13 / tyrannical

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

New client not launched on focused screen #84

Open jibbajabber opened 6 years ago

jibbajabber commented 6 years ago

Awesome 4.2 (dual screen setup) Tyrannical master branch

Launching a new application that has a matched class on multiple tags (on different screens), always ends up on the screen and tag that the application first ran/matched on.

Use case: Start firefox and launch on screen 1 tag 'www' (leave it running). Now focus on screen 2 tag 'www' and launch firefox, firefox is launched on screen 1 tag 'www' despite focus being on screen 2.

I have the following auto start method in my rc.lua

  function autostart_stuff()
      for s in screen do
          if s.index == 1 then
              awful.spawn("start_firefox", {screen = s, tag = "www"})
              awful.spawn("start_email", {screen = s, tag = "mail"})
          end
          if s.index == 2 then
  --              awful.spawn("charm", {screen = s, tag = "code"})
              awful.spawn("start_terminator", {screen = s, tag = "shell"})
          end
      end
  end

This works as expected and starts among others, a browser on screen 1, tag www.

However, once all auto started clients have launched, if I launch a new client using a mapped key on screen 2:

awful.key({ modkey,           }, "Return",
        function()
--            local s = awful.screen.focused({mouse = true})
--            awful.spawn('firefox', {screen = s, tag = 'www'})
            local t = awful.screen.focused({mouse = true}).selected_tag
            awful.spawn('firefox', {tag = t})
        end)

The new client will always start on screen 1 tag www, this occurs when using either the screen property (commented above) or the tag with screen focused reference. This does not happen without tyrannical.

Tyrannical config:

tyrannical.tags = {
    {
        name         = "www",
        init         = true,
        exclusive    = true,
        icon         = os.getenv("HOME").."/Pictures/awesome/browser.png",
        screen       = {1},
        layout       = awful.layout.suit.max,
        force_screen = true,
        class        = { "Firefox", "Google-chrome" }
    } ,
    {
        name         = "shell",                -- tag name
        init         = true,                   -- Load the tag on startup
        exclusive    = true,                   -- Refuse any other type of clients (by classes)
        icon         = os.getenv("HOME").."/Pictures/awesome/terminal.jpg",
        screen       = {1,2},                  -- Create this tag on screen 1 and screen 2
        force_screen = true,
        layout       = awful.layout.suit.tile, -- Use the tile layout
        class        = { "xterm", "terminator", "gnome-terminal" }
    } ,
    {
        name         = "www",
        init         = true,
        exclusive    = true,
        icon         = os.getenv("HOME").."/Pictures/awesome/browser.png",
        screen       = {2},
        force_screen = true,
        layout       = awful.layout.suit.max,
        class        = { "Google-chrome", "Firefox" }
    } ,
    {
        name         = "code",
        init         = true,
        exclusive    = true,
        icon         = os.getenv("HOME").."/Pictures/awesome/code.png",
        screen       = {1,2},
        layout       = awful.layout.suit.max,
        class        ={ "gedit", "code", 'jetbrains-pycharm' }
    } ,
    {
        name         = "files",
        init         = true,
        exclusive    = true,
        icon         = os.getenv("HOME").."/Pictures/awesome/folder.png",
        screen       = {1,2},
        layout       = awful.layout.suit.tile,
--        exec_once   = {"nautilus"}, --When the tag is accessed for the first time, execute this command
        class        = { "Nautilus" }
    } ,
    {
        name         = "docs",
        init         = true,
        exclusive    = true,
        icon         = os.getenv("HOME").."/Pictures/awesome/files.png",
        screen       = {1,2},
        layout       = awful.layout.suit.max,
        class        = {
            "Assistant"     , "Okular"         , "Evince"    , "EPDFviewer"   , "xpdf",
            "Xpdf"          ,                                        }
    } ,
    {
        name         = "mail",
        init         = true,
        exclusive    = true,
        icon         = os.getenv("HOME").."/Pictures/awesome/email.png",
        screen       = {1},
        layout       = awful.layout.suit.max,
        class        = { "Thunderbird"     , "Evolution" }
    } ,
    {
        name         = "any",
        init         = true,
        exclusive    = false,
        screen       = {2},
        layout       = awful.layout.suit.max
    } ,
}

-- Force the matching clients (by classes) to be centered on the screen on init
tyrannical.properties.placement = {
    kcalc = awful.placement.centered
}

tyrannical.settings.block_children_focus_stealing = true --Block popups ()
tyrannical.settings.group_children = true --Force popups/dialogs to have the same tags as the parent client
tyrannical.settings.favor_focused = true

Strangely this does not happen with the files tag, new nautilus clients are launched on the screen in focus, however new terminator terminals exhibit the same behavior (they are launched on screen 2 tag 'shell'; where auto start launched them)

After looking at issue 83 I added the following to make sure new clients that did not match were handled and added some extra debug to verify screen focus when launching on screen 2:

client.connect_signal("request::tag", function(c)
    local s = awful.screen.focused({mouse = true})
    f = io.open('/tmp/awesome_request_tag', 'a+')
    f:write('class:'..c.class..'\nname:'..c.name..'\nscreen index:'..c.screen.index..'\nscreen in focus index:'..s.index..'\n')

    if #c.screen.tags == 0 then
        f:write('Tag: MISSING\n\n')
        awful.tag.add("any", {layout = awful.layouts.layouts[1]})
    else
        f:write('first tag:'..c.first_tag.name..'\n\n')
    end
    f:close()
end)

I added the temporary io writes above for request tag signals to verify the focus was indeed on the screen that launched, the following logs confirmed that the focus was indeed the desired screen:

class:Firefox
name:Mozilla Firefox
screen index:1
screen in focus index:2
first tag:www

class:Terminator
name:None
screen index:2
screen in focus index:1
first tag:shell
basaran commented 5 years ago

Did you try using a single description for both screens like you have for the Files?

{
        name         = "www",
        init         = true,
        exclusive    = true,
        icon         = os.getenv("HOME").."/Pictures/awesome/browser.png",
        screen       = {1,2},
        layout       = awful.layout.suit.max,
        force_screen = true,
        class        = { "Firefox", "Google-chrome" }
} ,