Daniel Brötzmann pushed to branch mainwindow at gajim / gajim
Commits: ba694316 by wurstsalat at 2021-09-05T16:45:28+02:00 Add back restoring window position, size, visibility
- - - - -
5 changed files:
- gajim/common/setting_values.py - gajim/gtk/main.py - gajim/gtk/preferences.py - gajim/gtk/status_icon.py - gajim/gtk/util.py
Changes:
===================================== gajim/common/setting_values.py ===================================== @@ -46,23 +46,19 @@ class _ACCOUNT_DEFAULT: 'show_ascii_formatting_chars': True, 'sounds_on': True, 'gc_refer_to_nick_char': ',', - 'msgwin-max-state': False, - 'msgwin-x-position': -1, - 'msgwin-y-position': -1, - 'msgwin-width': 500, - 'msgwin-height': 440, - 'save-roster-position': True, - 'roster_x-position': 0, - 'roster_y-position': 0, - 'roster_width': 200, - 'roster_height': 400, + 'mainwin_x_position': 0, + 'mainwin_y_position': 0, + 'mainwin_width': 1000, + 'mainwin_height': 500, + 'save_main_window_position': True, + 'show_main_window_on_startup': 'always', + 'last_main_window_visible': True, 'roster_on_the_right': False, 'latest_disco_addresses': '', 'time_stamp': '%x | %X ', 'change_roster_title': True, 'restore_timeout': -1, 'send_on_ctrl_enter': False, - 'last_roster_visible': True, 'key_up_lines': 25, 'search_engine': 'https://duckduckgo.com/?q=%s', 'dictionary_url': 'WIKTIONARY', @@ -103,7 +99,6 @@ class _ACCOUNT_DEFAULT: 'roster_window_skip_taskbar': False, 'use_urgency_hint': True, 'notification_timeout': 5, - 'show_roster_on_startup': 'always', 'escape_key_closes': False, 'hide_groupchat_banner': False, 'hide_chat_banner': False, @@ -205,10 +200,6 @@ class _ACCOUNT_DEFAULT: 'file_transfer_proxies': '', 'use_ft_proxies': False, 'test_ft_proxies_on_startup': False, - 'msgwin-x-position': -1, - 'msgwin-y-position': -1, - 'msgwin-width': 480, - 'msgwin-height': 440, 'is_zeroconf': False, 'last_status': 'online', 'last_status_msg': '', @@ -373,7 +364,7 @@ class _ACCOUNT_DEFAULT: 'ascii_formatting': _('Treat * / _ pairs as possible formatting characters.'), 'show_ascii_formatting_chars': _('If enabled, do not remove */_ . So *abc* will be bold but with * * not removed.'), 'gc_refer_to_nick_char': _('Character to add after nickname when using nickname completion (tab) in group chat.'), - 'save-roster-position': _('If enabled, Gajim will save the contact list window position when hiding it, and restore it when showing the contact list window again.'), + 'save_main_window_position': _('If enabled, Gajim will save the main window position when hiding it, and restore it when showing the window again.'), 'roster_on_the_right': _('Place the contact list on the right in single window mode'), 'time_stamp': _('This option lets you customize the timestamp that is printed in conversation. For example '[%H:%M] ' will show '[hour:minute] '. See python doc on strftime for full documentation (https://docs.python.org/3/library/time.html#time.strftime).'), 'chat_timestamp_format': 'https://docs.python.org/3/library/time.html#time.strftime',
===================================== gajim/gtk/main.py ===================================== @@ -11,15 +11,17 @@ from gajim.common.i18n import _ from gajim.common.nec import EventHelper
-from gajim.gui.adhoc import AdHocCommand -from gajim.gui.account_side_bar import AccountSideBar -from gajim.gui.app_side_bar import AppSideBar -from gajim.gui.workspace_side_bar import WorkspaceSideBar -from gajim.gui.main_stack import MainStack -from gajim.gui.dialogs import DialogButton -from gajim.gui.dialogs import ConfirmationDialog -from gajim.gui.util import get_builder - +from .adhoc import AdHocCommand +from .account_side_bar import AccountSideBar +from .app_side_bar import AppSideBar +from .workspace_side_bar import WorkspaceSideBar +from .main_stack import MainStack +from .dialogs import DialogButton +from .dialogs import ConfirmationDialog +from .util import get_builder +from .util import resize_window +from .util import restore_main_window_position +from .util import save_main_window_position from .util import open_window
log = logging.getLogger('gajim.gui.main') @@ -30,10 +32,8 @@ def __init__(self): Gtk.ApplicationWindow.__init__(self) EventHelper.__init__(self) self.set_application(app.app) - self.set_position(Gtk.WindowPosition.CENTER) self.set_title('Gajim') self.set_default_icon_name('org.gajim.Gajim') - self.set_default_size(1000, 500)
app.window = self
@@ -89,7 +89,23 @@ def __init__(self): self._load_chats() self._add_actions() self._add_actions2() - self.show_all() + + restore_main_window_position() + window_width = app.settings.get('mainwin_width') + window_height = app.settings.get('mainwin_height') + resize_window(self, window_width, window_height) + + if app.settings.get('show_main_window_on_startup') == 'always': + self.show_all() + elif app.settings.get('show_main_window_on_startup') == 'never': + if app.settings.get('trayicon') != 'always': + # Without trayicon, we have to show the main window + self.show_all() + app.settings.set('last_main_window_visible', True) + else: + if (app.settings.get('last_main_window_visible') or + app.settings.get('trayicon') != 'always'): + self.show_all()
def _on_account_enabled(self, event): self._account_side_bar.add_account(event.account) @@ -495,6 +511,14 @@ def quit(self): get_msg = True break
+ save_main_window_position() + window_width, window_height = self.get_size() + app.settings.set('mainwin_width', window_width) + app.settings.set('mainwin_height', window_height) + app.settings.set( + 'last_main_window_visible', self.get_property('visible')) + app.settings.save() + def on_continue2(message): if 'file_transfers' not in app.interface.instances: app.app.start_shutdown(message=message)
===================================== gajim/gtk/preferences.py ===================================== @@ -165,7 +165,7 @@ def __init__(self, settings): class WindowBehaviour(PreferenceBox): def __init__(self, *args):
- roster_on_startup_items = { + main_window_on_startup_items = { 'always': _('Always'), 'never': _('Never'), 'last_state': _('Restore last state'), @@ -173,11 +173,11 @@ def __init__(self, *args):
settings = [ Setting(SettingKind.POPOVER, - _('Contact List on Startup'), + _('Show Gajim on Startup'), SettingType.CONFIG, - 'show_roster_on_startup', - props={'entries': roster_on_startup_items}, - desc=_('Show contact list when starting Gajim')), + 'show_main_window_on_startup', + props={'entries': main_window_on_startup_items}, + desc=_('Show window when starting Gajim')),
Setting(SettingKind.SWITCH, _('Quit on Close'),
===================================== gajim/gtk/status_icon.py ===================================== @@ -34,8 +34,8 @@
from .util import get_builder from .util import get_icon_name -from .util import save_roster_position -from .util import restore_roster_position +from .util import save_main_window_position +from .util import restore_main_window_position from .util import open_window
HAS_INDICATOR = False @@ -249,14 +249,14 @@ def _on_activate(self, *args): return
if app.window.get_property('has-toplevel-focus'): - save_roster_position(app.window) + save_main_window_position() app.window.hide() return
app.window.show_all() if not app.window.get_property('visible'): # Window was minimized - restore_roster_position(app.window) + restore_main_window_position()
if not app.settings.get('roster_window_skip_taskbar'): app.window.set_property('skip-taskbar-hint', False) @@ -268,7 +268,7 @@ def _handle_first_event(): if not event: return if not app.window.get_property('visible'): - restore_roster_position(app.window) + restore_main_window_position() app.interface.handle_event(account, jid, event.type_)
@staticmethod
===================================== gajim/gtk/util.py ===================================== @@ -312,10 +312,9 @@ def resize_window(window: Gtk.Window, width: int, height: int) -> None: screen_w, screen_h = get_total_screen_geometry() if not width or not height: return - if width > screen_w: - width = screen_w - if height > screen_h: - height = screen_h + + width = min(width, screen_w) + height = min(height, screen_h) window.resize(abs(width), abs(height))
@@ -324,10 +323,9 @@ def move_window(window: Gtk.Window, pos_x: int, pos_y: int) -> None: Move the window, but also check if out of screen """ screen_w, screen_h = get_total_screen_geometry() - if pos_x < 0: - pos_x = 0 - if pos_y < 0: - pos_y = 0 + pos_x = max(pos_x, 0) + pos_y = max(pos_y, 0) + width, height = window.get_size() if pos_x + width > screen_w: pos_x = screen_w - width @@ -336,25 +334,25 @@ def move_window(window: Gtk.Window, pos_x: int, pos_y: int) -> None: window.move(pos_x, pos_y)
-def save_roster_position(window): - if not app.settings.get('save-roster-position'): +def save_main_window_position() -> None: + if not app.settings.get('save_main_window_position'): return if app.is_display(Display.WAYLAND): return - x_pos, y_pos = window.get_position() - log.debug('Save roster position: %s %s', x_pos, y_pos) - app.settings.set('roster_x-position', x_pos) - app.settings.set('roster_y-position', y_pos) + x_pos, y_pos = app.window.get_position() + log.debug('Saving main window position: %s %s', x_pos, y_pos) + app.settings.set('mainwin_x_position', x_pos) + app.settings.set('mainwin_y_position', y_pos)
-def restore_roster_position(window): - if not app.settings.get('save-roster-position'): +def restore_main_window_position() -> None: + if not app.settings.get('save_main_window_position'): return if app.is_display(Display.WAYLAND): return - move_window(window, - app.settings.get('roster_x-position'), - app.settings.get('roster_y-position')) + move_window(app.window, + app.settings.get('mainwin_x_position'), + app.settings.get('mainwin_y_position'))
def get_completion_liststore(entry: Gtk.Entry) -> Gtk.ListStore:
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/ba6943163974af896c703ffc16f320f49...