Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for percentage in geometry #30

Open
henti opened this issue Oct 31, 2024 · 4 comments
Open

Add support for percentage in geometry #30

henti opened this issue Oct 31, 2024 · 4 comments
Labels
enhancement New feature or request workaround Can be mitigated (see comments/docs)

Comments

@henti
Copy link

henti commented Oct 31, 2024

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 dsalt added enhancement New feature or request workaround Can be mitigated (see comments/docs) labels Oct 31, 2024
@dsalt
Copy link
Owner

dsalt commented Oct 31, 2024

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
Copy link
Owner

dsalt commented Oct 31, 2024

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

@henti
Copy link
Author

henti commented Nov 18, 2024

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
Copy link
Owner

dsalt commented Nov 18, 2024

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…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request workaround Can be mitigated (see comments/docs)
Projects
None yet
Development

No branches or pull requests

2 participants