Daniel Brötzmann pushed to branch mainwindow at gajim / gajim
Commits:
-
ba694316
by wurstsalat at 2021-09-05T16:45:28+02:00
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:
| ... | ... | @@ -46,23 +46,19 @@ class _ACCOUNT_DEFAULT: |
| 46 | 46 |
'show_ascii_formatting_chars': True,
|
| 47 | 47 |
'sounds_on': True,
|
| 48 | 48 |
'gc_refer_to_nick_char': ',',
|
| 49 |
- 'msgwin-max-state': False,
|
|
| 50 |
- 'msgwin-x-position': -1,
|
|
| 51 |
- 'msgwin-y-position': -1,
|
|
| 52 |
- 'msgwin-width': 500,
|
|
| 53 |
- 'msgwin-height': 440,
|
|
| 54 |
- 'save-roster-position': True,
|
|
| 55 |
- 'roster_x-position': 0,
|
|
| 56 |
- 'roster_y-position': 0,
|
|
| 57 |
- 'roster_width': 200,
|
|
| 58 |
- 'roster_height': 400,
|
|
| 49 |
+ 'mainwin_x_position': 0,
|
|
| 50 |
+ 'mainwin_y_position': 0,
|
|
| 51 |
+ 'mainwin_width': 1000,
|
|
| 52 |
+ 'mainwin_height': 500,
|
|
| 53 |
+ 'save_main_window_position': True,
|
|
| 54 |
+ 'show_main_window_on_startup': 'always',
|
|
| 55 |
+ 'last_main_window_visible': True,
|
|
| 59 | 56 |
'roster_on_the_right': False,
|
| 60 | 57 |
'latest_disco_addresses': '',
|
| 61 | 58 |
'time_stamp': '%x | %X ',
|
| 62 | 59 |
'change_roster_title': True,
|
| 63 | 60 |
'restore_timeout': -1,
|
| 64 | 61 |
'send_on_ctrl_enter': False,
|
| 65 |
- 'last_roster_visible': True,
|
|
| 66 | 62 |
'key_up_lines': 25,
|
| 67 | 63 |
'search_engine': 'https://duckduckgo.com/?q=%s',
|
| 68 | 64 |
'dictionary_url': 'WIKTIONARY',
|
| ... | ... | @@ -103,7 +99,6 @@ class _ACCOUNT_DEFAULT: |
| 103 | 99 |
'roster_window_skip_taskbar': False,
|
| 104 | 100 |
'use_urgency_hint': True,
|
| 105 | 101 |
'notification_timeout': 5,
|
| 106 |
- 'show_roster_on_startup': 'always',
|
|
| 107 | 102 |
'escape_key_closes': False,
|
| 108 | 103 |
'hide_groupchat_banner': False,
|
| 109 | 104 |
'hide_chat_banner': False,
|
| ... | ... | @@ -205,10 +200,6 @@ class _ACCOUNT_DEFAULT: |
| 205 | 200 |
'file_transfer_proxies': '',
|
| 206 | 201 |
'use_ft_proxies': False,
|
| 207 | 202 |
'test_ft_proxies_on_startup': False,
|
| 208 |
- 'msgwin-x-position': -1,
|
|
| 209 |
- 'msgwin-y-position': -1,
|
|
| 210 |
- 'msgwin-width': 480,
|
|
| 211 |
- 'msgwin-height': 440,
|
|
| 212 | 203 |
'is_zeroconf': False,
|
| 213 | 204 |
'last_status': 'online',
|
| 214 | 205 |
'last_status_msg': '',
|
| ... | ... | @@ -373,7 +364,7 @@ class _ACCOUNT_DEFAULT: |
| 373 | 364 |
'ascii_formatting': _('Treat * / _ pairs as possible formatting characters.'),
|
| 374 | 365 |
'show_ascii_formatting_chars': _('If enabled, do not remove */_ . So *abc* will be bold but with * * not removed.'),
|
| 375 | 366 |
'gc_refer_to_nick_char': _('Character to add after nickname when using nickname completion (tab) in group chat.'),
|
| 376 |
- '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.'),
|
|
| 367 |
+ 'save_main_window_position': _('If enabled, Gajim will save the main window position when hiding it, and restore it when showing the window again.'),
|
|
| 377 | 368 |
'roster_on_the_right': _('Place the contact list on the right in single window mode'),
|
| 378 | 369 |
'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).'),
|
| 379 | 370 |
'chat_timestamp_format': 'https://docs.python.org/3/library/time.html#time.strftime',
|
| ... | ... | @@ -11,15 +11,17 @@ |
| 11 | 11 |
from gajim.common.i18n import _
|
| 12 | 12 |
from gajim.common.nec import EventHelper
|
| 13 | 13 |
|
| 14 |
-from gajim.gui.adhoc import AdHocCommand
|
|
| 15 |
-from gajim.gui.account_side_bar import AccountSideBar
|
|
| 16 |
-from gajim.gui.app_side_bar import AppSideBar
|
|
| 17 |
-from gajim.gui.workspace_side_bar import WorkspaceSideBar
|
|
| 18 |
-from gajim.gui.main_stack import MainStack
|
|
| 19 |
-from gajim.gui.dialogs import DialogButton
|
|
| 20 |
-from gajim.gui.dialogs import ConfirmationDialog
|
|
| 21 |
-from gajim.gui.util import get_builder
|
|
| 22 |
- |
|
| 14 |
+from .adhoc import AdHocCommand
|
|
| 15 |
+from .account_side_bar import AccountSideBar
|
|
| 16 |
+from .app_side_bar import AppSideBar
|
|
| 17 |
+from .workspace_side_bar import WorkspaceSideBar
|
|
| 18 |
+from .main_stack import MainStack
|
|
| 19 |
+from .dialogs import DialogButton
|
|
| 20 |
+from .dialogs import ConfirmationDialog
|
|
| 21 |
+from .util import get_builder
|
|
| 22 |
+from .util import resize_window
|
|
| 23 |
+from .util import restore_main_window_position
|
|
| 24 |
+from .util import save_main_window_position
|
|
| 23 | 25 |
from .util import open_window
|
| 24 | 26 |
|
| 25 | 27 |
log = logging.getLogger('gajim.gui.main')
|
| ... | ... | @@ -30,10 +32,8 @@ def __init__(self): |
| 30 | 32 |
Gtk.ApplicationWindow.__init__(self)
|
| 31 | 33 |
EventHelper.__init__(self)
|
| 32 | 34 |
self.set_application(app.app)
|
| 33 |
- self.set_position(Gtk.WindowPosition.CENTER)
|
|
| 34 | 35 |
self.set_title('Gajim')
|
| 35 | 36 |
self.set_default_icon_name('org.gajim.Gajim')
|
| 36 |
- self.set_default_size(1000, 500)
|
|
| 37 | 37 |
|
| 38 | 38 |
app.window = self
|
| 39 | 39 |
|
| ... | ... | @@ -89,7 +89,23 @@ def __init__(self): |
| 89 | 89 |
self._load_chats()
|
| 90 | 90 |
self._add_actions()
|
| 91 | 91 |
self._add_actions2()
|
| 92 |
- self.show_all()
|
|
| 92 |
+ |
|
| 93 |
+ restore_main_window_position()
|
|
| 94 |
+ window_width = app.settings.get('mainwin_width')
|
|
| 95 |
+ window_height = app.settings.get('mainwin_height')
|
|
| 96 |
+ resize_window(self, window_width, window_height)
|
|
| 97 |
+ |
|
| 98 |
+ if app.settings.get('show_main_window_on_startup') == 'always':
|
|
| 99 |
+ self.show_all()
|
|
| 100 |
+ elif app.settings.get('show_main_window_on_startup') == 'never':
|
|
| 101 |
+ if app.settings.get('trayicon') != 'always':
|
|
| 102 |
+ # Without trayicon, we have to show the main window
|
|
| 103 |
+ self.show_all()
|
|
| 104 |
+ app.settings.set('last_main_window_visible', True)
|
|
| 105 |
+ else:
|
|
| 106 |
+ if (app.settings.get('last_main_window_visible') or
|
|
| 107 |
+ app.settings.get('trayicon') != 'always'):
|
|
| 108 |
+ self.show_all()
|
|
| 93 | 109 |
|
| 94 | 110 |
def _on_account_enabled(self, event):
|
| 95 | 111 |
self._account_side_bar.add_account(event.account)
|
| ... | ... | @@ -495,6 +511,14 @@ def quit(self): |
| 495 | 511 |
get_msg = True
|
| 496 | 512 |
break
|
| 497 | 513 |
|
| 514 |
+ save_main_window_position()
|
|
| 515 |
+ window_width, window_height = self.get_size()
|
|
| 516 |
+ app.settings.set('mainwin_width', window_width)
|
|
| 517 |
+ app.settings.set('mainwin_height', window_height)
|
|
| 518 |
+ app.settings.set(
|
|
| 519 |
+ 'last_main_window_visible', self.get_property('visible'))
|
|
| 520 |
+ app.settings.save()
|
|
| 521 |
+ |
|
| 498 | 522 |
def on_continue2(message):
|
| 499 | 523 |
if 'file_transfers' not in app.interface.instances:
|
| 500 | 524 |
app.app.start_shutdown(message=message)
|
| ... | ... | @@ -165,7 +165,7 @@ def __init__(self, settings): |
| 165 | 165 |
class WindowBehaviour(PreferenceBox):
|
| 166 | 166 |
def __init__(self, *args):
|
| 167 | 167 |
|
| 168 |
- roster_on_startup_items = {
|
|
| 168 |
+ main_window_on_startup_items = {
|
|
| 169 | 169 |
'always': _('Always'),
|
| 170 | 170 |
'never': _('Never'),
|
| 171 | 171 |
'last_state': _('Restore last state'),
|
| ... | ... | @@ -173,11 +173,11 @@ def __init__(self, *args): |
| 173 | 173 |
|
| 174 | 174 |
settings = [
|
| 175 | 175 |
Setting(SettingKind.POPOVER,
|
| 176 |
- _('Contact List on Startup'),
|
|
| 176 |
+ _('Show Gajim on Startup'),
|
|
| 177 | 177 |
SettingType.CONFIG,
|
| 178 |
- 'show_roster_on_startup',
|
|
| 179 |
- props={'entries': roster_on_startup_items},
|
|
| 180 |
- desc=_('Show contact list when starting Gajim')),
|
|
| 178 |
+ 'show_main_window_on_startup',
|
|
| 179 |
+ props={'entries': main_window_on_startup_items},
|
|
| 180 |
+ desc=_('Show window when starting Gajim')),
|
|
| 181 | 181 |
|
| 182 | 182 |
Setting(SettingKind.SWITCH,
|
| 183 | 183 |
_('Quit on Close'),
|
| ... | ... | @@ -34,8 +34,8 @@ |
| 34 | 34 |
|
| 35 | 35 |
from .util import get_builder
|
| 36 | 36 |
from .util import get_icon_name
|
| 37 |
-from .util import save_roster_position
|
|
| 38 |
-from .util import restore_roster_position
|
|
| 37 |
+from .util import save_main_window_position
|
|
| 38 |
+from .util import restore_main_window_position
|
|
| 39 | 39 |
from .util import open_window
|
| 40 | 40 |
|
| 41 | 41 |
HAS_INDICATOR = False
|
| ... | ... | @@ -249,14 +249,14 @@ def _on_activate(self, *args): |
| 249 | 249 |
return
|
| 250 | 250 |
|
| 251 | 251 |
if app.window.get_property('has-toplevel-focus'):
|
| 252 |
- save_roster_position(app.window)
|
|
| 252 |
+ save_main_window_position()
|
|
| 253 | 253 |
app.window.hide()
|
| 254 | 254 |
return
|
| 255 | 255 |
|
| 256 | 256 |
app.window.show_all()
|
| 257 | 257 |
if not app.window.get_property('visible'):
|
| 258 | 258 |
# Window was minimized
|
| 259 |
- restore_roster_position(app.window)
|
|
| 259 |
+ restore_main_window_position()
|
|
| 260 | 260 |
|
| 261 | 261 |
if not app.settings.get('roster_window_skip_taskbar'):
|
| 262 | 262 |
app.window.set_property('skip-taskbar-hint', False)
|
| ... | ... | @@ -268,7 +268,7 @@ def _handle_first_event(): |
| 268 | 268 |
if not event:
|
| 269 | 269 |
return
|
| 270 | 270 |
if not app.window.get_property('visible'):
|
| 271 |
- restore_roster_position(app.window)
|
|
| 271 |
+ restore_main_window_position()
|
|
| 272 | 272 |
app.interface.handle_event(account, jid, event.type_)
|
| 273 | 273 |
|
| 274 | 274 |
@staticmethod
|
| ... | ... | @@ -312,10 +312,9 @@ def resize_window(window: Gtk.Window, width: int, height: int) -> None: |
| 312 | 312 |
screen_w, screen_h = get_total_screen_geometry()
|
| 313 | 313 |
if not width or not height:
|
| 314 | 314 |
return
|
| 315 |
- if width > screen_w:
|
|
| 316 |
- width = screen_w
|
|
| 317 |
- if height > screen_h:
|
|
| 318 |
- height = screen_h
|
|
| 315 |
+ |
|
| 316 |
+ width = min(width, screen_w)
|
|
| 317 |
+ height = min(height, screen_h)
|
|
| 319 | 318 |
window.resize(abs(width), abs(height))
|
| 320 | 319 |
|
| 321 | 320 |
|
| ... | ... | @@ -324,10 +323,9 @@ def move_window(window: Gtk.Window, pos_x: int, pos_y: int) -> None: |
| 324 | 323 |
Move the window, but also check if out of screen
|
| 325 | 324 |
"""
|
| 326 | 325 |
screen_w, screen_h = get_total_screen_geometry()
|
| 327 |
- if pos_x < 0:
|
|
| 328 |
- pos_x = 0
|
|
| 329 |
- if pos_y < 0:
|
|
| 330 |
- pos_y = 0
|
|
| 326 |
+ pos_x = max(pos_x, 0)
|
|
| 327 |
+ pos_y = max(pos_y, 0)
|
|
| 328 |
+ |
|
| 331 | 329 |
width, height = window.get_size()
|
| 332 | 330 |
if pos_x + width > screen_w:
|
| 333 | 331 |
pos_x = screen_w - width
|
| ... | ... | @@ -336,25 +334,25 @@ def move_window(window: Gtk.Window, pos_x: int, pos_y: int) -> None: |
| 336 | 334 |
window.move(pos_x, pos_y)
|
| 337 | 335 |
|
| 338 | 336 |
|
| 339 |
-def save_roster_position(window):
|
|
| 340 |
- if not app.settings.get('save-roster-position'):
|
|
| 337 |
+def save_main_window_position() -> None:
|
|
| 338 |
+ if not app.settings.get('save_main_window_position'):
|
|
| 341 | 339 |
return
|
| 342 | 340 |
if app.is_display(Display.WAYLAND):
|
| 343 | 341 |
return
|
| 344 |
- x_pos, y_pos = window.get_position()
|
|
| 345 |
- log.debug('Save roster position: %s %s', x_pos, y_pos)
|
|
| 346 |
- app.settings.set('roster_x-position', x_pos)
|
|
| 347 |
- app.settings.set('roster_y-position', y_pos)
|
|
| 342 |
+ x_pos, y_pos = app.window.get_position()
|
|
| 343 |
+ log.debug('Saving main window position: %s %s', x_pos, y_pos)
|
|
| 344 |
+ app.settings.set('mainwin_x_position', x_pos)
|
|
| 345 |
+ app.settings.set('mainwin_y_position', y_pos)
|
|
| 348 | 346 |
|
| 349 | 347 |
|
| 350 |
-def restore_roster_position(window):
|
|
| 351 |
- if not app.settings.get('save-roster-position'):
|
|
| 348 |
+def restore_main_window_position() -> None:
|
|
| 349 |
+ if not app.settings.get('save_main_window_position'):
|
|
| 352 | 350 |
return
|
| 353 | 351 |
if app.is_display(Display.WAYLAND):
|
| 354 | 352 |
return
|
| 355 |
- move_window(window,
|
|
| 356 |
- app.settings.get('roster_x-position'),
|
|
| 357 |
- app.settings.get('roster_y-position'))
|
|
| 353 |
+ move_window(app.window,
|
|
| 354 |
+ app.settings.get('mainwin_x_position'),
|
|
| 355 |
+ app.settings.get('mainwin_y_position'))
|
|
| 358 | 356 |
|
| 359 | 357 |
|
| 360 | 358 |
def get_completion_liststore(entry: Gtk.Entry) -> Gtk.ListStore:
|