Skip to content

Commit

Permalink
Access: Minor Rework (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marukesu authored Jan 18, 2023
1 parent 1c47d7a commit 70a4c6c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 32 deletions.
43 changes: 21 additions & 22 deletions src/Access/Dialog.vala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021 elementary, Inc. (https://elementary.io)
* SPDX-FileCopyrightText: 2021-2023 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: LGPL-2.1-or-later
*/

Expand All @@ -10,8 +10,6 @@ public class Access.Dialog : Granite.MessageDialog {
DESTRUCTIVE
}

public uint register_id { get; set; default = 0; }

public ButtonAction action { get; construct; }

public string parent_window { get; construct; }
Expand All @@ -38,8 +36,8 @@ public class Access.Dialog : Granite.MessageDialog {
}
}

private Gtk.Button grant_button;
private Gtk.Button deny_button;
private unowned Gtk.Button grant_button;
private unowned Gtk.Button deny_button;
private List<Choice> choices;

public Dialog (ButtonAction action, string app_id, string parent_window, string icon) {
Expand Down Expand Up @@ -75,27 +73,28 @@ public class Access.Dialog : Granite.MessageDialog {

custom_bin.orientation = Gtk.Orientation.VERTICAL;
custom_bin.spacing = 6;
}

public override void show () {
((Gtk.Widget) base).realize ();

unowned var toplevel = (Gdk.Toplevel) get_surface ();

if (parent_window != "") {
((Gtk.Widget) this).realize.connect (() => {
unowned var surface = get_surface ();

if (surface is Gdk.X11.Surface) {
unowned var x11_surface = (Gdk.X11.Surface) surface;
x11_surface.set_skip_taskbar_hint (true);
}

try {
ExternalWindow.from_handle (parent_window).set_parent_of (surface);
} catch (Error e) {
warning ("Failed to associate portal window with parent %s: %s", parent_window, e.message);
}
});
try {
ExternalWindow.from_handle (parent_window).set_parent_of (toplevel);
} catch (Error e) {
warning ("Failed to associate portal window with parent '%s': %s", parent_window, e.message);
}
}

show.connect (() => {
present_with_time (Gdk.CURRENT_TIME);
});
base.show ();
toplevel.focus (Gdk.CURRENT_TIME);
}

public override void close () {
response (Gtk.ResponseType.CANCEL);
base.close ();
}

[DBus (visible = false)]
Expand Down
24 changes: 14 additions & 10 deletions src/Access/Portal.vala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021 elementary, Inc. (https://elementary.io)
* SPDX-FileCopyrightText: 2021-2023 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: LGPL-2.1-or-later
*/

Expand All @@ -24,6 +24,7 @@ public class Access.Portal : Object {
) throws DBusError, IOError {
Dialog.ButtonAction action = Dialog.ButtonAction.SUGGESTED;
string icon = "dialog-information";
uint register_id = 0;

if ("destructive" in options && options["destructive"].get_boolean ()) {
action = Dialog.ButtonAction.DESTRUCTIVE;
Expand Down Expand Up @@ -61,19 +62,13 @@ public class Access.Portal : Object {
}
}

try {
dialog.register_id = connection.register_object (handle, dialog);
} catch (Error e) {
critical (e.message);
}

var _results = new HashTable<string, Variant> (str_hash, str_equal);
uint _response = 2;
var _response = 2;

dialog.response.connect ((id) => {
switch (id) {
case Gtk.ResponseType.OK:
VariantBuilder choices_builder = new VariantBuilder (new VariantType ("a(ss)"));
var choices_builder = new VariantBuilder (new VariantType ("a(ss)"));

dialog.get_choices ().foreach ((choice) => {
choices_builder.add ("(ss)", choice.name, choice.selected);
Expand All @@ -82,9 +77,11 @@ public class Access.Portal : Object {
_results["choices"] = choices_builder.end ();
_response = 0;
break;

case Gtk.ResponseType.CANCEL:
_response = 1;
break;

case Gtk.ResponseType.DELETE_EVENT:
_response = 2;
break;
Expand All @@ -93,10 +90,17 @@ public class Access.Portal : Object {
access_dialog.callback ();
});

try {
register_id = connection.register_object (handle, dialog);
} catch (IOError e) {
warning (e.message);
throw new DBusError.OBJECT_PATH_IN_USE (e.message);
}

dialog.present ();
yield;

connection.unregister_object (dialog.register_id);
connection.unregister_object (register_id);
dialog.destroy ();

results = _results;
Expand Down

0 comments on commit 70a4c6c

Please sign in to comment.