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