Skip to content

Commit

Permalink
Automatically choose the best layout for the screen
Browse files Browse the repository at this point in the history
  • Loading branch information
hongquan committed Sep 12, 2021
1 parent 59e8bab commit 5f72563
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions cobang/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def do_activate(self):
self.discover_webcam()
self.window.present()
logger.debug("Window {} is shown", self.window)
ui.resize_to_match_screen(self.window)
# If no webcam is selected, select the first V4l2 one
if not self.webcam_combobox.get_active_iter():
v4l2_idx = next((n for n, r in enumerate(self.webcam_store) if r[2] == 'v4l2src'), 0)
Expand Down
25 changes: 25 additions & 0 deletions cobang/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

logger = Logger(__name__)

BEST_HORIZONTAL_WIDTH = 914
BEST_VERTICAL_HEIGHT = 654


def build_app_menu_model() -> Gio.Menu:
menu = Gio.Menu()
Expand Down Expand Up @@ -86,3 +89,25 @@ def wifi_connect_done(client: NM.Client, res: Gio.AsyncResult, button: Gtk.Butto
if created:
button.set_label(_('Saved'))
button.set_sensitive(False)


def get_monitor_screen(window: Gtk.Window):
display = window.get_display()
logger.debug('Display: {}, {}', display, display.get_name())
# FIXME: It returns wrong monitor
monitor = display.get_monitor_at_window(window.get_window())
geo = monitor.get_geometry()
w, h = geo.width, geo.height
logger.debug('Monitor size: {}', (w, h))
return (w, h)


def resize_to_match_screen(window: Gtk.Window):
'''Try to detect desktop or mobile screen, and resize to promote the horizontal or vertical layout.'''
sw, sh = get_monitor_screen(window)
w, h = window.get_size()
logger.debug('Current window size: {}', (w, h))
if sw > BEST_HORIZONTAL_WIDTH:
window.resize(BEST_HORIZONTAL_WIDTH, h)
elif sh > BEST_VERTICAL_HEIGHT:
window.resize(w, BEST_VERTICAL_HEIGHT)
5 changes: 5 additions & 0 deletions data/vn.hoabinh.quan.CoBang.appdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
</kudos>

<releases>
<release version="0.9.3" date="2021-09-12" urgency="medium">
<description>
<p>Automatically choose the best layout for the screen.</p>
</description>
</release>
<release version="0.9.2" date="2021-09-11" urgency="medium">
<description>
<p>Reduce scrolling on mobile screen.</p>
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project('cobang',
version: '0.9.2',
version: '0.9.3',
meson_version: '>= 0.53',
default_options: [
'warning_level=2',
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cobang"
version = "0.9.2"
version = "0.9.3"
description = "QR code scanner for Linux desktop"
authors = ["Nguyễn Hồng Quân <[email protected]>"]
license = "GPL-3.0-or-later"
Expand Down

0 comments on commit 5f72563

Please sign in to comment.