fix: don't save window_x/y anymore

As per GNOME HIG, let the DE position the window, but continue to store
the window width and height
This commit is contained in:
Romain Failliot 2023-04-16 11:35:36 -04:00
parent feb557d99b
commit ef3d59d87b
1 changed files with 23 additions and 25 deletions

View File

@ -682,24 +682,18 @@ class DiffuseWindow(Gtk.ApplicationWindow):
# number of created viewers (used to label some tabs)
self.viewer_count = 0
# get monitor resolution
monitor_geometry = Gdk.Display.get_default().get_monitor(0).get_geometry()
# state information that should persist across sessions
self.bool_state = {
'window_maximized': False,
'search_matchcase': False,
'search_backwards': False
}
self.int_state = {'window_width': 1024, 'window_height': 768}
self.int_state['window_x'] = max(
0,
(monitor_geometry.width - self.int_state['window_width']) / 2
)
self.int_state['window_y'] = max(
0,
(monitor_geometry.height - self.int_state['window_height']) / 2
)
self.int_state = {
'window_width': 1024,
'window_height': 768,
}
# window state signals
self.connect('configure-event', self.configure_cb)
self.connect('window-state-event', self.window_state_cb)
@ -989,15 +983,13 @@ class DiffuseWindow(Gtk.ApplicationWindow):
# read the state directly instead of using window_maximized as the order
# of configure/window_state events is undefined
if (widget.get_window().get_state() & Gdk.WindowState.MAXIMIZED) == 0:
self.int_state['window_x'], self.int_state['window_y'] = widget.get_window().get_root_origin() # noqa: E501
self.int_state['window_width'] = event.width
self.int_state['window_height'] = event.height
# record the window's maximized state
def window_state_cb(self, window, event):
self.bool_state['window_maximized'] = (
(event.new_window_state & Gdk.WindowState.MAXIMIZED) != 0
)
def window_state_cb(self, widget: Gtk.Widget, event: Gdk.EventWindowState) -> None:
is_maximized = (event.new_window_state & Gdk.WindowState.MAXIMIZED) != 0
self.bool_state['window_maximized'] = is_maximized
# load state information that should persist across sessions
def load_state(self, statepath: str) -> None:
@ -1006,14 +998,20 @@ class DiffuseWindow(Gtk.ApplicationWindow):
f = open(statepath, 'r')
ss = utils.readlines(f)
f.close()
for j, s in enumerate(ss):
try:
a = shlex.split(s, True)
if len(a) > 0:
if len(a) == 2 and a[0] in self.bool_state:
self.bool_state[a[0]] = (a[1] == 'True')
elif len(a) == 2 and a[0] in self.int_state:
self.int_state[a[0]] = int(a[1])
if len(a) == 0:
continue
if len(a) != 2:
raise ValueError()
(key, value) = a
if key in self.bool_state:
self.bool_state[key] = (value == 'True')
elif key in self.int_state:
self.int_state[key] = int(value)
else:
raise ValueError()
except ValueError:
@ -1024,7 +1022,6 @@ class DiffuseWindow(Gtk.ApplicationWindow):
# bad $HOME value? -- don't bother the user
utils.logDebug(f'Error reading {statepath}.')
self.move(self.int_state['window_x'], self.int_state['window_y'])
self.resize(self.int_state['window_width'], self.int_state['window_height'])
if self.bool_state['window_maximized']:
self.maximize()
@ -1038,6 +1035,7 @@ class DiffuseWindow(Gtk.ApplicationWindow):
for k, v in self.int_state.items():
ss.append(f'{k} {v}\n')
ss.sort()
f = open(statepath, 'w')
f.write(f'# This state file was generated by {constants.APP_NAME} {constants.VERSION}.\n\n') # noqa: E501
for s in ss: