Skip to content

Commit ef3d59d

Browse files
committed
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
1 parent feb557d commit ef3d59d

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

src/diffuse/window.py

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -682,24 +682,18 @@ def __init__(self, rc_dir, **kwargs):
682682
# number of created viewers (used to label some tabs)
683683
self.viewer_count = 0
684684

685-
# get monitor resolution
686-
monitor_geometry = Gdk.Display.get_default().get_monitor(0).get_geometry()
687-
688685
# state information that should persist across sessions
689686
self.bool_state = {
690687
'window_maximized': False,
691688
'search_matchcase': False,
692689
'search_backwards': False
693690
}
694-
self.int_state = {'window_width': 1024, 'window_height': 768}
695-
self.int_state['window_x'] = max(
696-
0,
697-
(monitor_geometry.width - self.int_state['window_width']) / 2
698-
)
699-
self.int_state['window_y'] = max(
700-
0,
701-
(monitor_geometry.height - self.int_state['window_height']) / 2
702-
)
691+
self.int_state = {
692+
'window_width': 1024,
693+
'window_height': 768,
694+
}
695+
696+
# window state signals
703697
self.connect('configure-event', self.configure_cb)
704698
self.connect('window-state-event', self.window_state_cb)
705699

@@ -989,15 +983,13 @@ def configure_cb(self, widget: Gtk.Widget, event: Gdk.EventConfigure) -> None:
989983
# read the state directly instead of using window_maximized as the order
990984
# of configure/window_state events is undefined
991985
if (widget.get_window().get_state() & Gdk.WindowState.MAXIMIZED) == 0:
992-
self.int_state['window_x'], self.int_state['window_y'] = widget.get_window().get_root_origin() # noqa: E501
993986
self.int_state['window_width'] = event.width
994987
self.int_state['window_height'] = event.height
995988

996989
# record the window's maximized state
997-
def window_state_cb(self, window, event):
998-
self.bool_state['window_maximized'] = (
999-
(event.new_window_state & Gdk.WindowState.MAXIMIZED) != 0
1000-
)
990+
def window_state_cb(self, widget: Gtk.Widget, event: Gdk.EventWindowState) -> None:
991+
is_maximized = (event.new_window_state & Gdk.WindowState.MAXIMIZED) != 0
992+
self.bool_state['window_maximized'] = is_maximized
1001993

1002994
# load state information that should persist across sessions
1003995
def load_state(self, statepath: str) -> None:
@@ -1006,16 +998,22 @@ def load_state(self, statepath: str) -> None:
1006998
f = open(statepath, 'r')
1007999
ss = utils.readlines(f)
10081000
f.close()
1001+
10091002
for j, s in enumerate(ss):
10101003
try:
10111004
a = shlex.split(s, True)
1012-
if len(a) > 0:
1013-
if len(a) == 2 and a[0] in self.bool_state:
1014-
self.bool_state[a[0]] = (a[1] == 'True')
1015-
elif len(a) == 2 and a[0] in self.int_state:
1016-
self.int_state[a[0]] = int(a[1])
1017-
else:
1018-
raise ValueError()
1005+
if len(a) == 0:
1006+
continue
1007+
if len(a) != 2:
1008+
raise ValueError()
1009+
1010+
(key, value) = a
1011+
if key in self.bool_state:
1012+
self.bool_state[key] = (value == 'True')
1013+
elif key in self.int_state:
1014+
self.int_state[key] = int(value)
1015+
else:
1016+
raise ValueError()
10191017
except ValueError:
10201018
# this may happen if the state was written by a
10211019
# different version -- don't bother the user
@@ -1024,7 +1022,6 @@ def load_state(self, statepath: str) -> None:
10241022
# bad $HOME value? -- don't bother the user
10251023
utils.logDebug(f'Error reading {statepath}.')
10261024

1027-
self.move(self.int_state['window_x'], self.int_state['window_y'])
10281025
self.resize(self.int_state['window_width'], self.int_state['window_height'])
10291026
if self.bool_state['window_maximized']:
10301027
self.maximize()
@@ -1038,6 +1035,7 @@ def save_state(self, statepath: str) -> None:
10381035
for k, v in self.int_state.items():
10391036
ss.append(f'{k} {v}\n')
10401037
ss.sort()
1038+
10411039
f = open(statepath, 'w')
10421040
f.write(f'# This state file was generated by {constants.APP_NAME} {constants.VERSION}.\n\n') # noqa: E501
10431041
for s in ss:

0 commit comments

Comments
 (0)