[GTK] Fix and cleanup storing window position

This commit is contained in:
Calum Lind 2018-11-06 11:19:00 +00:00
parent 2bb9a8e71c
commit 83cac4978a
1 changed files with 11 additions and 16 deletions

View File

@ -158,11 +158,7 @@ class MainWindow(component.Component):
def hide(self): def hide(self):
component.get('TorrentView').save_state() component.get('TorrentView').save_state()
component.pause(self.child_components) component.pause(self.child_components)
self.save_position()
# Store the x, y positions for when we restore the window
self.config['window_x_pos'], self.config[
'window_y_pos'
] = self.window.get_position()
self.window.hide() self.window.hide()
def present(self): def present(self):
@ -193,7 +189,7 @@ class MainWindow(component.Component):
def visible(self): def visible(self):
"""Returns True if window is visible, False if not.""" """Returns True if window is visible, False if not."""
return self.window.get_property('visible') return self.window.get_visible()
def get_builder(self): def get_builder(self):
"""Returns a reference to the main window GTK builder object.""" """Returns a reference to the main window GTK builder object."""
@ -250,21 +246,20 @@ class MainWindow(component.Component):
if self.config['window_maximized']: if self.config['window_maximized']:
self.window.maximize() self.window.maximize()
def on_window_configure_event(self, widget, event): def save_position(self):
if not self.config['window_maximized'] and self.visible: self.config['window_maximized'] = self.window.props.is_maximized
if not self.config['window_maximized'] and self.visible():
self.config['window_x_pos'], self.config[ self.config['window_x_pos'], self.config[
'window_y_pos' 'window_y_pos'
] = self.window.get_position() ] = self.window.get_position()
self.config['window_width'] = event.width self.config['window_width'], self.config[
self.config['window_height'] = event.height 'window_height'
] = self.window.get_size()
def on_window_configure_event(self, widget, event):
self.save_position()
def on_window_state_event(self, widget, event): def on_window_state_event(self, widget, event):
if event.changed_mask & WindowState.MAXIMIZED:
if event.new_window_state & WindowState.MAXIMIZED:
log.debug('pos: %s', self.window.get_position())
self.config['window_maximized'] = True
elif not event.new_window_state & WindowState.WITHDRAWN:
self.config['window_maximized'] = False
if event.changed_mask & WindowState.ICONIFIED: if event.changed_mask & WindowState.ICONIFIED:
if event.new_window_state & WindowState.ICONIFIED: if event.new_window_state & WindowState.ICONIFIED:
log.debug('MainWindow is minimized..') log.debug('MainWindow is minimized..')