mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-11 05:17:59 +03:00
console: Fix and simplify 'Resize to VM' action
We need to resize the window and not try to play crazy games with the scroll window size. Wish I realized this years ago...
This commit is contained in:
parent
21e29a4178
commit
eea9b27696
@ -127,7 +127,6 @@ class vmmConsolePages(vmmGObjectUI):
|
|||||||
self._pointer_is_grabbed = False
|
self._pointer_is_grabbed = False
|
||||||
self._change_title()
|
self._change_title()
|
||||||
self.vm.connect("state-changed", self._change_title)
|
self.vm.connect("state-changed", self._change_title)
|
||||||
self._force_resize = False
|
|
||||||
|
|
||||||
# State for disabling modifiers when keyboard is grabbed
|
# State for disabling modifiers when keyboard is grabbed
|
||||||
self._accel_groups = Gtk.accel_groups_from_object(self.topwin)
|
self._accel_groups = Gtk.accel_groups_from_object(self.topwin)
|
||||||
@ -357,8 +356,9 @@ class vmmConsolePages(vmmGObjectUI):
|
|||||||
###########################
|
###########################
|
||||||
|
|
||||||
def _scroll_size_allocate(self, src_ignore, req):
|
def _scroll_size_allocate(self, src_ignore, req):
|
||||||
if (not self._viewer or
|
if not self._viewer:
|
||||||
not self._viewer.console_get_desktop_resolution()):
|
return
|
||||||
|
if not self._viewer.console_get_desktop_resolution():
|
||||||
return
|
return
|
||||||
|
|
||||||
scroll = self.widget("console-gfx-scroll")
|
scroll = self.widget("console-gfx-scroll")
|
||||||
@ -371,27 +371,24 @@ class vmmConsolePages(vmmGObjectUI):
|
|||||||
|
|
||||||
# pylint: disable=unpacking-non-sequence
|
# pylint: disable=unpacking-non-sequence
|
||||||
desktop_w, desktop_h = self._viewer.console_get_desktop_resolution()
|
desktop_w, desktop_h = self._viewer.console_get_desktop_resolution()
|
||||||
if desktop_h == 0:
|
|
||||||
return
|
|
||||||
desktop_ratio = float(desktop_w) / float(desktop_h)
|
desktop_ratio = float(desktop_w) / float(desktop_h)
|
||||||
|
|
||||||
if is_scale or self._force_resize:
|
if is_scale:
|
||||||
# Make sure we never show scrollbars when scaling
|
# Make sure we never show scrollbars when scaling
|
||||||
scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.NEVER)
|
scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.NEVER)
|
||||||
else:
|
else:
|
||||||
scroll.set_policy(Gtk.PolicyType.AUTOMATIC,
|
scroll.set_policy(Gtk.PolicyType.AUTOMATIC,
|
||||||
Gtk.PolicyType.AUTOMATIC)
|
Gtk.PolicyType.AUTOMATIC)
|
||||||
|
|
||||||
if not self._force_resize and is_resizeguest:
|
if is_resizeguest:
|
||||||
# With resize guest, we don't want to maintain aspect ratio,
|
# With resize guest, we don't want to maintain aspect ratio,
|
||||||
# since the guest can resize to arbitrary resolutions.
|
# since the guest can resize to arbitrary resolutions.
|
||||||
self._viewer.console_set_size_request(req.width, req.height)
|
self._viewer.console_set_size_request(req.width, req.height)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not is_scale or self._force_resize:
|
if not is_scale:
|
||||||
# Scaling disabled is easy, just force the VNC widget size. Since
|
# Scaling disabled is easy, just force the VNC widget size. Since
|
||||||
# we are inside a scrollwindow, it shouldn't cause issues.
|
# we are inside a scrollwindow, it shouldn't cause issues.
|
||||||
self._force_resize = False
|
|
||||||
self._viewer.console_set_size_request(desktop_w, desktop_h)
|
self._viewer.console_set_size_request(desktop_w, desktop_h)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -458,10 +455,14 @@ class vmmConsolePages(vmmGObjectUI):
|
|||||||
if not self._viewer.console_get_desktop_resolution():
|
if not self._viewer.console_get_desktop_resolution():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
topwin_alloc = self.topwin.get_allocation()
|
||||||
|
viewer_alloc = self.widget("console-gfx-scroll").get_allocation()
|
||||||
|
desktop_w, desktop_h = self._viewer.console_get_desktop_resolution()
|
||||||
|
|
||||||
self.topwin.unmaximize()
|
self.topwin.unmaximize()
|
||||||
self.topwin.resize(1, 1)
|
self.topwin.resize(
|
||||||
self._force_resize = True
|
desktop_w + (topwin_alloc.width - viewer_alloc.width),
|
||||||
self.widget("console-gfx-scroll").queue_resize()
|
desktop_h + (topwin_alloc.height - viewer_alloc.height))
|
||||||
|
|
||||||
|
|
||||||
################
|
################
|
||||||
|
@ -258,7 +258,14 @@ class Viewer(vmmGObject):
|
|||||||
return self._get_grab_keys()
|
return self._get_grab_keys()
|
||||||
|
|
||||||
def console_get_desktop_resolution(self):
|
def console_get_desktop_resolution(self):
|
||||||
return self._get_desktop_resolution()
|
ret = self._get_desktop_resolution()
|
||||||
|
if not ret:
|
||||||
|
return ret
|
||||||
|
|
||||||
|
# Don't pass on bogus resolutions
|
||||||
|
if (ret[0] == 0) or (ret[1] == 0):
|
||||||
|
return None
|
||||||
|
return ret
|
||||||
|
|
||||||
def console_get_scaling(self):
|
def console_get_scaling(self):
|
||||||
return self._get_scaling()
|
return self._get_scaling()
|
||||||
|
Loading…
Reference in New Issue
Block a user