dsalt / devilspie2

Devilspie2 is a window matching utility, allowing the user to perform scripted actions on windows as they are opened and closed.
GNU General Public License v3.0
135 stars 15 forks source link

Add support for percentage in geometry #30

Open henti opened 3 weeks ago

henti commented 3 weeks ago

I'm not sure how viable this is, but I switching between different screen sizes due to "hot desking", so being able to set geometry as percentage of screen would be very handy. For instance,

Laptop : 1920x1200 Attached Monitor : 2560x1440

if (get_application_name() == "Pixel 6") then
  --x, y, width, height = get_window_geometry();
  --print(x..", "..y..", "..width..", "..height);
  set_window_geometry(1920, 0, 630, 1440);
  set_window_workspace(8);
end

sets my scrcpy window for maximum height and width for my pixel 6 screen at the left edge position on second monitor (arranged right of laptop, see below) image

but if I'm attached to a 4k monitor, this position will be wrong. Being able to set geometry as a percentage (possibly with some calculation based on preset monitor resolutions) would be very handy and will make auto scaling base don attached monitor much nicer.

dsalt commented 3 weeks ago

It's not difficult to do that kind of thing with the existing Lua functions if you use get_monitor_geometry, set_window_position (with a monitor number) and set_window_size instead of set_window_geometry.

More calculation may be needed, of course, depending on exactly how you want to position the window; but, in this case, the following should do:

function set_window_geometry_percent(x,y,w,h,m)
  local _,_,W,H = get_monitor_geometry(m)
  if _ == nil then
    -- monitor not found
    if m ~= 1 then set_window_geometry_percent(x,y,w,h,1) end
  else
    set_window_position(x*W, y*H, m)
    set_window_size(w*W, h*H)
  end
end

if get_application_name() == "Pixel 6" then
  -- assumption: the monitor is 16:9
  set_window_geometry_percent(0, 0, 630/2560, 1, 2);
  set_window_workspace(8);
end
dsalt commented 3 weeks ago

FWIW, set_window_geometry has just sprouted an optional monitor number parameter.

henti commented 6 days ago

thank you for all the information. unfortunately I'm on 0.43 so this is not available to me and Debian seems unlikely to upgrade anytime soon. I'll have to look at rolling my own package or PPA, but thank you for the response and information :)

dsalt commented 6 days ago

You should file a bug report there about the package being out of date – but note that it's handled by their QA team, so yes, nothing much will probably happen. It's probably going to take somebody building it (starting from the existing Debian packaging) and getting a Debian dev to sponsor it for upload to unstable…