mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
details: Remember previous window dimensions
In order to do this, we can't auto resize the window to the VNC desktop resolution when details is brought up. So, to make this desired behavior easier, add a View menu item 'Resize to VM' which resizes the details window to match the active desktop dimensions.
This commit is contained in:
parent
436d1c39e2
commit
8b31e9afc3
@ -186,7 +186,9 @@ class vmmConfig:
|
||||
try:
|
||||
self.conf_dir = newconf
|
||||
if func_type == self._PEROBJ_FUNC_SET:
|
||||
pref_func(value)
|
||||
if type(value) is not tuple:
|
||||
value = (value,)
|
||||
pref_func(*value)
|
||||
elif func_type == self._PEROBJ_FUNC_GET:
|
||||
ret = pref_func()
|
||||
elif func_type == self._PEROBJ_FUNC_LISTEN:
|
||||
@ -196,7 +198,7 @@ class vmmConfig:
|
||||
|
||||
return ret
|
||||
|
||||
def set_pervm(self, uri, uuid, pref_func, value):
|
||||
def set_pervm(self, uri, uuid, pref_func, args):
|
||||
"""
|
||||
@param uri: VM connection URI
|
||||
@param uuid: VM UUID
|
||||
@ -204,7 +206,7 @@ class vmmConfig:
|
||||
@param pref_func: Global preference get/set/listen func that the
|
||||
pervm instance will overshadow
|
||||
"""
|
||||
self._pervm_helper(uri, uuid, pref_func, self._PEROBJ_FUNC_SET, value)
|
||||
self._pervm_helper(uri, uuid, pref_func, self._PEROBJ_FUNC_SET, args)
|
||||
def get_pervm(self, uri, uuid, pref_func):
|
||||
ret = self._pervm_helper(uri, uuid, pref_func, self._PEROBJ_FUNC_GET)
|
||||
if ret == None:
|
||||
@ -413,6 +415,14 @@ class vmmConfig:
|
||||
def set_details_show_toolbar(self, state):
|
||||
self.conf.set_bool(self.conf_dir + "/details/show-toolbar", state)
|
||||
|
||||
# VM details default size
|
||||
def get_details_window_size(self):
|
||||
w = self.conf.get_int(self.conf_dir + "/details/window_width")
|
||||
h = self.conf.get_int(self.conf_dir + "/details/window_height")
|
||||
return (w, h)
|
||||
def set_details_window_size(self, w, h):
|
||||
self.conf.set_int(self.conf_dir + "/details/window_width", w)
|
||||
self.conf.set_int(self.conf_dir + "/details/window_height", h)
|
||||
|
||||
# Create sound device for default guest
|
||||
def get_local_sound(self):
|
||||
|
@ -305,6 +305,16 @@ class vmmConsolePages(gobject.GObject):
|
||||
|
||||
self.update_scaling()
|
||||
|
||||
def size_to_vm(self, src):
|
||||
# Resize the console to best fit the VM resolution
|
||||
if not self.desktop_resolution:
|
||||
return
|
||||
|
||||
w, h = self.desktop_resolution
|
||||
self.topwin.unmaximize()
|
||||
self.topwin.resize(1, 1)
|
||||
self.queue_resize_helper("console-vnc-scroll", w, h)
|
||||
|
||||
def send_key(self, src):
|
||||
keys = None
|
||||
if src.get_name() == "details-menu-send-cad":
|
||||
@ -624,7 +634,7 @@ class vmmConsolePages(gobject.GObject):
|
||||
|
||||
def desktop_resize(self, src, w, h):
|
||||
self.desktop_resolution = (w, h)
|
||||
self.queue_resize_helper("console-vnc-scroll", w, h)
|
||||
self.window.get_widget("console-vnc-scroll").queue_resize()
|
||||
|
||||
def queue_resize_helper(self, widget_name, w, h):
|
||||
"""
|
||||
|
@ -127,6 +127,10 @@ class vmmDetails(gobject.GObject):
|
||||
self.console = vmmConsolePages(self.config, self.vm, self.engine,
|
||||
self.window)
|
||||
|
||||
# Set default window size
|
||||
w, h = self.vm.get_details_window_size()
|
||||
self.topwin.set_default_size(w or 800, h or 600)
|
||||
|
||||
self.init_menus()
|
||||
self.init_details()
|
||||
|
||||
@ -146,6 +150,7 @@ class vmmDetails(gobject.GObject):
|
||||
"on_close_details_clicked": self.close,
|
||||
"on_details_menu_close_activate": self.close,
|
||||
"on_vmm_details_delete_event": self.close,
|
||||
"on_vmm_details_configure_event": self.window_resized,
|
||||
"on_details_menu_quit_activate": self.exit_app,
|
||||
|
||||
"on_control_vm_details_toggled": self.details_console_changed,
|
||||
@ -198,6 +203,7 @@ class vmmDetails(gobject.GObject):
|
||||
|
||||
# Listeners stored in vmmConsolePages
|
||||
"on_details_menu_view_fullscreen_activate": self.console.toggle_fullscreen,
|
||||
"on_details_menu_view_size_to_vm_activate": self.console.size_to_vm,
|
||||
"on_details_menu_view_scale_always_toggled": self.console.set_scale_type,
|
||||
"on_details_menu_view_scale_fullscreen_toggled": self.console.set_scale_type,
|
||||
"on_details_menu_view_scale_never_toggled": self.console.set_scale_type,
|
||||
@ -443,6 +449,13 @@ class vmmDetails(gobject.GObject):
|
||||
# Window state listeners #
|
||||
##########################
|
||||
|
||||
def window_resized(self, ignore, event):
|
||||
# Sometimes dimensions change when window isn't visible
|
||||
if not self.is_visible():
|
||||
return
|
||||
|
||||
self.vm.set_details_window_size(event.width, event.height)
|
||||
|
||||
def populate_serial_menu(self, src):
|
||||
for ent in src:
|
||||
src.remove(ent)
|
||||
|
@ -819,6 +819,12 @@ class vmmDomain(gobject.GObject):
|
||||
self.config.listen_pervm(self.connection.get_uri(), self.uuid,
|
||||
self.config.on_console_scaling_changed, cb)
|
||||
|
||||
def set_details_window_size(self, w, h):
|
||||
self.config.set_pervm(self.connection.get_uri(), self.uuid,
|
||||
self.config.set_details_window_size, (w, h))
|
||||
def get_details_window_size(self):
|
||||
return self.config.get_pervm(self.connection.get_uri(), self.uuid,
|
||||
self.config.get_details_window_size)
|
||||
|
||||
def _sample_mem_stats(self, info):
|
||||
pcentCurrMem = info[2] * 100.0 / self.connection.host_memory_size()
|
||||
|
@ -6,6 +6,7 @@
|
||||
<property name="title" translatable="yes">Virtual Machine</property>
|
||||
<property name="default_width">800</property>
|
||||
<property name="default_height">600</property>
|
||||
<signal name="configure_event" handler="on_vmm_details_configure_event"/>
|
||||
<signal name="delete_event" handler="on_vmm_details_delete_event"/>
|
||||
<child>
|
||||
<widget class="GtkVBox" id="vbox2">
|
||||
@ -238,6 +239,14 @@
|
||||
<signal name="activate" handler="on_details_menu_view_fullscreen_activate"/>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkMenuItem" id="detains-menu-view-size-to-vm">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">_Resize to VM</property>
|
||||
<property name="use_underline">True</property>
|
||||
<signal name="activate" handler="on_details_menu_view_size_to_vm_activate"/>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkMenuItem" id="menuitem1">
|
||||
<property name="visible">True</property>
|
||||
|
Loading…
Reference in New Issue
Block a user