Autostart program in specific workspace

I use autstart as outlined in the documentation. All programs start in the first workspace. Is there a way to specify a different workspace on a per program basis? Thank you!

2 Likes

With KDE it’s possible:

And also with XFCE (the default desktop environment). But I’m not sure how.

1 Like

Use devilspie2, which can be installed via sudo qubes-dom0-update devilspie2

Then under ~/.config/devilspie2/ create ws.lua

In it write this:

qube = get_window_property("_QUBES_VMNAME");
ws = 0;

if qube == "personal" then ws = 1;
if qube == "work" then ws = 2;

if ws > 0 then

	set_window_workspace(ws);
	change_workspace(ws);

end
5 Likes

Duplicate discussion here:

Thank you very much for pointing me to devilspie2! I did not know that such a good thing exists. What I was looking for was for instance placing a “personal” firefox in workspace 1, a “personal” thunderbird in 2 and a “vault” keepassxc in 4. I will look into lua scripts for that.
Thanks again.

I was searching for “autostart” so I overlooked it. Sorry!

No worries :slight_smile:

You may find this useful:

workspace_associations = {};
workspace_associations["personal-signal"] = 1;
workspace_associations["personal-email"] = 2;
workspace_associations["personal-vault"] = 3;

fullscreen_apps = {"Signal", "Thunderbird", "KeePassXC", "Firefox"}

domain = get_window_property('_QUBES_VMNAME');
if (domain == "") then
	domain = "dom0";
elseif (string.find(string.lower(domain), "disp")) then
	domain = "disp";
end

application = get_application_name();

window = get_window_name();

debug_print("Domain: " .. domain);
debug_print("Application: " .. application);
debug_print("Window: " .. window);

-- If the domain has a workspace association, then move the window to that workspace.
if (workspace_associations[domain] ~= nil and workspace_associations[domain] <= get_workspace_count()) then
	workspace_number = workspace_associations[domain];
	debug_print("Moving " .. application .. " to workspace " .. workspace_number .. "\n");
	set_window_workspace(workspace_number);
end

-- Maximize all fullscreen applications.
for _, fullscreen_app in ipairs(fullscreen_apps) do
	if (string.find(string.lower(window), string.lower(fullscreen_app))) then
		debug_print("Maximizing " .. application  .. "\n");
		maximize();
	end
end
3 Likes

Thank you very much. I will try it out and report back.

I am sorry I do not fully understand this.

The .lua file should be created at the Dom0? Or the template?

If I try to autostart an .AppImage file when a Qube is starting where do I have to include the filepath to the .AppImage?

In dom0:

  • sudo qubes-dom0-update devilspie2
  • add devilspie2 under “Application Autostart | Session and Startup” in the XFCE Settings app
  • put the .lua file under ~/.config/devilspie2
  • make sure the .lua file contains the code you need, what I posted was just an example how to make sure a window of a specific qube shows on a specific workspace

You would create a .desktop file for it and locate it under ~/.config/autostart in that qube.

1 Like

What code would be a way to include dipsxxx based on template-yyy in this? Or per application name started, regardless of the VM name (vlc, for instance)?

Here some inspirations for you to play with:

      w_screen, h_screen = get_screen_geometry();
                win_name = get_window_name();
                win_type = get_window_type();
                win_role = get_window_role();
               win_class = get_class_instance_name();
                    qube = get_window_property("_QUBES_VMNAME");

Checkout devilspie2 documentation and search for some samples. There is nothing qubes specific here (except for the _QUBES_VMNAME window property).

local function compare(t, s, n)

   if n==1 then
     return t:sub(n, s:len())==s;
   else
     return t:sub(-s:len())==s;
   end
end

if compare(win_class, "keepassxc", 0) or
    compare(win_class, "evince", 0)   then
   
[...]

   elseif compare(win_class, "Msgcompose", 0) then
   

(“Msgcompose” is Thunderbirds compose window)

Have fun!

1 Like

Indeed, Obviously the pie looked too devilish and tempting enough to overlooked it, but thanks a lot and please apologize! :slight_smile:

1 Like

Fix your error and format your code

qube = get_window_property("_QUBES_VMNAME");
ws = 0;

if qube == "personal" then
      ws = 1
elseif qube == "work" then
      ws = 2
end

if ws > 0 then
  set_window_workspace(ws);
  change_workspace(ws);
end
1 Like

If you want to put many qubes at same window

qube = get_window_property("_QUBES_VMNAME");
ws = 0;

local function has_value (array, val)
    for index, value in ipairs(array) do
        if value == val then
            return true
        end
    end

    return false
end

if has_value({'work, personal'}, qube) then
      ws = 1
elseif has_value({'vault'}, qube) then
      ws = 2
end

if ws > 0 then
  set_window_workspace(ws);
  change_workspace(ws);
end
2 Likes