Skip to content

Commit c5f22b5

Browse files
committed
Last round of review fixes
1 parent b237806 commit c5f22b5

File tree

6 files changed

+1080
-1028
lines changed

6 files changed

+1080
-1028
lines changed

qubes_config/global_config.glade

Lines changed: 1040 additions & 1004 deletions
Large diffs are not rendered by default.

qubes_config/global_config/device_attachments.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ def run_for_new(self, new_row_function: Callable) -> DevPolicyRow:
509509
self._init_check(self.no_strict_check, False, False, "not selected")
510510
self._init_check(self.port_check, False, False, "not selected")
511511

512+
self.dev_combo.set_active_id(None)
512513
self.unknown_box.set_visible(False)
513514
self.qube_handler.reset()
514515
self.validate()
@@ -989,7 +990,7 @@ def __init__(
989990
prefix="devices_auto",
990991
device_policy_manager=self.device_manager,
991992
classes=["block", "mic", "usb"],
992-
assignment_filter=self._filter_required,
993+
assignment_filter=self._filter_auto,
993994
edit_dialog_class=AutoDeviceDialog,
994995
)
995996
self.required_devices_handler = AttachmentHandler(
@@ -998,7 +999,7 @@ def __init__(
998999
prefix="devices_required",
9991000
device_policy_manager=self.device_manager,
10001001
classes=["block", "pci"],
1001-
assignment_filter=self._filter_auto,
1002+
assignment_filter=self._filter_required,
10021003
edit_dialog_class=RequiredDeviceDialog,
10031004
)
10041005

qubes_config/global_config/device_widgets.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import gi
2727

28-
from ..widgets.gtk_utils import ask_question
28+
from ..widgets.gtk_utils import ask_question, resize_window_to_reasonable
2929

3030
gi.require_version("Gtk", "3.0")
3131
from gi.repository import Gtk
@@ -146,6 +146,11 @@ def __init__(
146146
self.ok_button.connect("clicked", self._save_changes)
147147
self.cancel_button.connect("clicked", self._cancel)
148148

149+
self.dialog.connect("size-allocate", self._resize_window)
150+
151+
def _resize_window(self, *_args):
152+
resize_window_to_reasonable(self.dialog)
153+
149154
def _cancel(self, *_args):
150155
if self.remove_on_cancel and self.current_row:
151156
self.current_row.get_parent().remove(self.current_row)
@@ -176,6 +181,7 @@ def run_for_new(self, new_row_function: Callable) -> DevPolicyRow:
176181
self.remove_on_cancel = True
177182

178183
self.dialog.show()
184+
self._resize_window()
179185

180186
return new_row
181187

@@ -185,6 +191,7 @@ def run_for_existing(self, row: DevPolicyRow):
185191
self.validate()
186192
self.remove_on_cancel = False
187193
self.dialog.show()
194+
self._resize_window()
188195

189196
def validate(self, *_args):
190197
"""Connect this function to any events that should trigger

qubes_config/global_config/global_config.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
show_dialog_with_icon,
3636
load_theme,
3737
is_theme_light,
38+
resize_window_to_reasonable,
3839
)
3940
from ..widgets.gtk_widgets import ProgressBarDialog, ViewportHandler
4041
from ..widgets.utils import open_url_in_disposable
@@ -299,27 +300,7 @@ def do_activate(self, *args, **kwargs):
299300
self.perform_setup()
300301
assert self.main_window
301302
self.main_window.show()
302-
# resize to screen size
303-
if (
304-
self.main_window.get_allocated_width()
305-
> self.main_window.get_screen().get_width()
306-
):
307-
width = int(self.main_window.get_screen().get_width() * 0.9)
308-
else:
309-
# try to have at least 1100 pixels
310-
width = min(int(self.main_window.get_screen().get_width() * 0.9), 1100)
311-
if (
312-
self.main_window.get_allocated_height()
313-
> self.main_window.get_screen().get_height() * 0.9
314-
):
315-
height = int(self.main_window.get_screen().get_height() * 0.9)
316-
else:
317-
height = self.main_window.get_allocated_height()
318-
self.main_window.resize(width, height)
319-
self.main_window.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
320-
self.main_window.set_gravity(Gdk.Gravity.CENTER)
321-
self.main_window.move(0, 0)
322-
self.main_window.set_position(Gtk.WindowPosition.CENTER)
303+
resize_window_to_reasonable(self.main_window)
323304

324305
# open at specified location
325306
if self.open_at:

qubes_config/global_config/vm_flowbox.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ def __init__(
138138
filter_function=filter_function,
139139
)
140140

141+
self.add_qube_model.connect_change_callback(self._check_for_add_validity)
142+
141143
self.flowbox.set_sort_func(self._sort_flowbox)
142144
self.placeholder = PlaceholderText()
143145
self.flowbox.add(self.placeholder)
@@ -151,6 +153,12 @@ def __init__(
151153
self.add_button.connect("clicked", self._add_confirm_clicked)
152154
self.flowbox.connect("child-removed", self._vm_removed)
153155

156+
def _check_for_add_validity(self, *_args):
157+
if self.add_qube_model.get_selected() is None:
158+
self.add_button.set_sensitive(False)
159+
else:
160+
self.add_button.set_sensitive(True)
161+
154162
@staticmethod
155163
def _sort_flowbox(child_1, child_2):
156164
vm_1 = str(child_1)

qubes_config/widgets/gtk_utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,22 @@ def copy_to_global_clipboard(text: str):
275275
source.write("dom0")
276276
with open(XEVENT, "w", encoding="ascii") as timestamp:
277277
timestamp.write(str(Gtk.get_current_event_time()))
278+
279+
280+
def resize_window_to_reasonable(window: Gtk.Window, min_width: int = 1100):
281+
"""Make sure the provided window is visible and does not exceed available screen
282+
space."""
283+
if window.get_allocated_width() > window.get_screen().get_width():
284+
width = int(window.get_screen().get_width() * 0.9)
285+
else:
286+
# try to have at least min_width pixels
287+
width = min(int(window.get_screen().get_width() * 0.9), min_width)
288+
if window.get_allocated_height() > window.get_screen().get_height() * 0.9:
289+
height = int(window.get_screen().get_height() * 0.9)
290+
else:
291+
height = window.get_allocated_height()
292+
window.resize(width, height)
293+
window.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
294+
window.set_gravity(Gdk.Gravity.CENTER)
295+
window.move(0, 0)
296+
window.set_position(Gtk.WindowPosition.CENTER)

0 commit comments

Comments
 (0)