code review:

- implement blueprints for Adwaita 1.2
- use postifx notation for casting gtk widgets
- fix formatting
This commit is contained in:
Maciej Bartczak
2025-03-05 21:01:49 +01:00
parent f71b294697
commit bd617c52e9
11 changed files with 365 additions and 110 deletions

View File

@ -27,8 +27,8 @@ core_surface: *CoreSurface,
pending_req: apprt.ClipboardRequest, pending_req: apprt.ClipboardRequest,
text_view: *gtk.TextView, text_view: *gtk.TextView,
text_view_scroll: *gtk.ScrolledWindow, text_view_scroll: *gtk.ScrolledWindow,
reveal_button_widget: *gtk.Widget, reveal_button: *gtk.Button,
hide_button_widget: *gtk.Widget, hide_button: *gtk.Button,
pub fn create( pub fn create(
app: *App, app: *App,
@ -101,8 +101,8 @@ fn init(
.pending_req = request, .pending_req = request,
.text_view = text_view, .text_view = text_view,
.text_view_scroll = text_view_scroll, .text_view_scroll = text_view_scroll,
.reveal_button_widget = gobject.ext.cast(gtk.Widget, reveal_button).?, .reveal_button = reveal_button,
.hide_button_widget = gobject.ext.cast(gtk.Widget, hide_button).?, .hide_button = hide_button,
}; };
const buffer = gtk.TextBuffer.new(null); const buffer = gtk.TextBuffer.new(null);
@ -111,10 +111,10 @@ fn init(
text_view.setBuffer(buffer); text_view.setBuffer(buffer);
if (is_secure_input) { if (is_secure_input) {
gobject.ext.as(gtk.Widget, text_view_scroll).setSensitive(@intFromBool(false)); text_view_scroll.as(gtk.Widget).setSensitive(@intFromBool(false));
gobject.ext.as(gtk.Widget, self.text_view).addCssClass("blurred"); self.text_view.as(gtk.Widget).addCssClass("blurred");
self.reveal_button_widget.setVisible(@intFromBool(true)); self.reveal_button.as(gtk.Widget).setVisible(@intFromBool(true));
_ = gtk.Button.signals.clicked.connect( _ = gtk.Button.signals.clicked.connect(
reveal_button, reveal_button,
@ -189,17 +189,17 @@ fn gtkResponse(_: *DialogType, response: [*:0]u8, self: *ClipboardConfirmation)
} }
fn gtkRevealButtonClicked(_: *gtk.Button, self: *ClipboardConfirmation) callconv(.C) void { fn gtkRevealButtonClicked(_: *gtk.Button, self: *ClipboardConfirmation) callconv(.C) void {
gobject.ext.as(gtk.Widget, self.text_view_scroll).setSensitive(@intFromBool(true)); self.text_view_scroll.as(gtk.Widget).setSensitive(@intFromBool(true));
gobject.ext.as(gtk.Widget, self.text_view).removeCssClass("blurred"); self.text_view.as(gtk.Widget).removeCssClass("blurred");
self.hide_button_widget.setVisible(@intFromBool(true)); self.hide_button.as(gtk.Widget).setVisible(@intFromBool(true));
self.reveal_button_widget.setVisible(@intFromBool(false)); self.reveal_button.as(gtk.Widget).setVisible(@intFromBool(false));
} }
fn gtkHideButtonClicked(_: *gtk.Button, self: *ClipboardConfirmation) callconv(.C) void { fn gtkHideButtonClicked(_: *gtk.Button, self: *ClipboardConfirmation) callconv(.C) void {
gobject.ext.as(gtk.Widget, self.text_view_scroll).setSensitive(@intFromBool(false)); self.text_view_scroll.as(gtk.Widget).setSensitive(@intFromBool(false));
gobject.ext.as(gtk.Widget, self.text_view).addCssClass("blurred"); self.text_view.as(gtk.Widget).addCssClass("blurred");
self.hide_button_widget.setVisible(@intFromBool(false)); self.hide_button.as(gtk.Widget).setVisible(@intFromBool(false));
self.reveal_button_widget.setVisible(@intFromBool(true)); self.reveal_button.as(gtk.Widget).setVisible(@intFromBool(true));
} }

View File

@ -1209,7 +1209,13 @@ fn gtkClipboardRead(
error.UnauthorizedPaste, error.UnauthorizedPaste,
=> { => {
// Create a dialog and ask the user if they want to paste anyway. // Create a dialog and ask the user if they want to paste anyway.
ClipboardConfirmationWindow.create(self.app, str, &self.core_surface, req.state, self.is_secure_input) catch |window_err| { ClipboardConfirmationWindow.create(
self.app,
str,
&self.core_surface,
req.state,
self.is_secure_input,
) catch |window_err| {
log.err("failed to create clipboard confirmation window err={}", .{window_err}); log.err("failed to create clipboard confirmation window err={}", .{window_err});
}; };
return; return;
@ -2224,7 +2230,13 @@ fn doPaste(self: *Surface, data: [:0]const u8) void {
error.UnsafePaste, error.UnsafePaste,
error.UnauthorizedPaste, error.UnauthorizedPaste,
=> { => {
ClipboardConfirmationWindow.create(self.app, data, &self.core_surface, .paste, self.is_secure_input) catch |window_err| { ClipboardConfirmationWindow.create(
self.app,
data,
&self.core_surface,
.paste,
self.is_secure_input,
) catch |window_err| {
log.err("failed to create clipboard confirmation window err={}", .{window_err}); log.err("failed to create clipboard confirmation window err={}", .{window_err});
}; };
}, },

View File

@ -14,7 +14,12 @@ Adw.MessageDialog clipboard_confirmation_window {
default-response: "cancel"; default-response: "cancel";
close-response: "cancel"; close-response: "cancel";
extra-child: ScrolledWindow { extra-child: Overlay {
styles [
"osd"
]
ScrolledWindow text_view_scroll {
width-request: 500; width-request: 500;
height-request: 250; height-request: 250;
@ -26,6 +31,41 @@ Adw.MessageDialog clipboard_confirmation_window {
left-margin: 8; left-margin: 8;
bottom-margin: 8; bottom-margin: 8;
right-margin: 8; right-margin: 8;
styles [
"clipboard-content-view"
]
}
}
[overlay]
Button reveal_button {
visible: false;
halign: end;
valign: start;
margin-end: 12;
margin-top: 12;
Image {
icon-name: "view-reveal-symbolic";
}
}
[overlay]
Button hide_button {
visible: false;
halign: end;
valign: start;
margin-end: 12;
margin-top: 12;
styles [
"opaque"
]
Image {
icon-name: "view-conceal-symbolic";
}
} }
}; };
} }

View File

@ -7,16 +7,21 @@ corresponding .blp file and regenerate this file with blueprint-compiler.
<interface domain="com.mitchellh.ghostty"> <interface domain="com.mitchellh.ghostty">
<requires lib="gtk" version="4.0"/> <requires lib="gtk" version="4.0"/>
<object class="AdwMessageDialog" id="clipboard_confirmation_window"> <object class="AdwMessageDialog" id="clipboard_confirmation_window">
<property name="heading" translatable="yes">Authorize Clipboard Access</property> <property name="heading" translatable="true">Authorize Clipboard Access</property>
<property name="body" translatable="yes">An application is attempting to read from the clipboard. The current clipboard contents are shown below.</property> <property name="body" translatable="true">An application is attempting to read from the clipboard. The current clipboard contents are shown below.</property>
<responses> <responses>
<response id="cancel" translatable="yes" appearance="suggested">Deny</response> <response id="cancel" translatable="true" appearance="suggested">Deny</response>
<response id="ok" translatable="yes" appearance="destructive">Allow</response> <response id="ok" translatable="true" appearance="destructive">Allow</response>
</responses> </responses>
<property name="default-response">cancel</property> <property name="default-response">cancel</property>
<property name="close-response">cancel</property> <property name="close-response">cancel</property>
<property name="extra-child"> <property name="extra-child">
<object class="GtkScrolledWindow"> <object class="GtkOverlay">
<style>
<class name="osd"/>
</style>
<child>
<object class="GtkScrolledWindow" id="text_view_scroll">
<property name="width-request">500</property> <property name="width-request">500</property>
<property name="height-request">250</property> <property name="height-request">250</property>
<child> <child>
@ -28,6 +33,42 @@ corresponding .blp file and regenerate this file with blueprint-compiler.
<property name="left-margin">8</property> <property name="left-margin">8</property>
<property name="bottom-margin">8</property> <property name="bottom-margin">8</property>
<property name="right-margin">8</property> <property name="right-margin">8</property>
<style>
<class name="clipboard-content-view"/>
</style>
</object>
</child>
</object>
</child>
<child type="overlay">
<object class="GtkButton" id="reveal_button">
<property name="visible">false</property>
<property name="halign">2</property>
<property name="valign">1</property>
<property name="margin-end">12</property>
<property name="margin-top">12</property>
<child>
<object class="GtkImage">
<property name="icon-name">view-reveal-symbolic</property>
</object>
</child>
</object>
</child>
<child type="overlay">
<object class="GtkButton" id="hide_button">
<property name="visible">false</property>
<property name="halign">2</property>
<property name="valign">1</property>
<property name="margin-end">12</property>
<property name="margin-top">12</property>
<style>
<class name="opaque"/>
</style>
<child>
<object class="GtkImage">
<property name="icon-name">view-conceal-symbolic</property>
</object>
</child>
</object> </object>
</child> </child>
</object> </object>

View File

@ -14,7 +14,12 @@ Adw.MessageDialog clipboard_confirmation_window {
default-response: "cancel"; default-response: "cancel";
close-response: "cancel"; close-response: "cancel";
extra-child: ScrolledWindow { extra-child: Overlay {
styles [
"osd"
]
ScrolledWindow text_view_scroll {
width-request: 500; width-request: 500;
height-request: 250; height-request: 250;
@ -26,6 +31,41 @@ Adw.MessageDialog clipboard_confirmation_window {
left-margin: 8; left-margin: 8;
bottom-margin: 8; bottom-margin: 8;
right-margin: 8; right-margin: 8;
styles [
"clipboard-content-view"
]
}
}
[overlay]
Button reveal_button {
visible: false;
halign: end;
valign: start;
margin-end: 12;
margin-top: 12;
Image {
icon-name: "view-reveal-symbolic";
}
}
[overlay]
Button hide_button {
visible: false;
halign: end;
valign: start;
margin-end: 12;
margin-top: 12;
styles [
"opaque"
]
Image {
icon-name: "view-conceal-symbolic";
}
} }
}; };
} }

View File

@ -7,16 +7,21 @@ corresponding .blp file and regenerate this file with blueprint-compiler.
<interface domain="com.mitchellh.ghostty"> <interface domain="com.mitchellh.ghostty">
<requires lib="gtk" version="4.0"/> <requires lib="gtk" version="4.0"/>
<object class="AdwMessageDialog" id="clipboard_confirmation_window"> <object class="AdwMessageDialog" id="clipboard_confirmation_window">
<property name="heading" translatable="yes">Authorize Clipboard Access</property> <property name="heading" translatable="true">Authorize Clipboard Access</property>
<property name="body" translatable="yes">An application is attempting to write to the clipboard. The current clipboard contents are shown below.</property> <property name="body" translatable="true">An application is attempting to write to the clipboard. The current clipboard contents are shown below.</property>
<responses> <responses>
<response id="cancel" translatable="yes" appearance="suggested">Deny</response> <response id="cancel" translatable="true" appearance="suggested">Deny</response>
<response id="ok" translatable="yes" appearance="destructive">Allow</response> <response id="ok" translatable="true" appearance="destructive">Allow</response>
</responses> </responses>
<property name="default-response">cancel</property> <property name="default-response">cancel</property>
<property name="close-response">cancel</property> <property name="close-response">cancel</property>
<property name="extra-child"> <property name="extra-child">
<object class="GtkScrolledWindow"> <object class="GtkOverlay">
<style>
<class name="osd"/>
</style>
<child>
<object class="GtkScrolledWindow" id="text_view_scroll">
<property name="width-request">500</property> <property name="width-request">500</property>
<property name="height-request">250</property> <property name="height-request">250</property>
<child> <child>
@ -28,6 +33,42 @@ corresponding .blp file and regenerate this file with blueprint-compiler.
<property name="left-margin">8</property> <property name="left-margin">8</property>
<property name="bottom-margin">8</property> <property name="bottom-margin">8</property>
<property name="right-margin">8</property> <property name="right-margin">8</property>
<style>
<class name="clipboard-content-view"/>
</style>
</object>
</child>
</object>
</child>
<child type="overlay">
<object class="GtkButton" id="reveal_button">
<property name="visible">false</property>
<property name="halign">2</property>
<property name="valign">1</property>
<property name="margin-end">12</property>
<property name="margin-top">12</property>
<child>
<object class="GtkImage">
<property name="icon-name">view-reveal-symbolic</property>
</object>
</child>
</object>
</child>
<child type="overlay">
<object class="GtkButton" id="hide_button">
<property name="visible">false</property>
<property name="halign">2</property>
<property name="valign">1</property>
<property name="margin-end">12</property>
<property name="margin-top">12</property>
<style>
<class name="opaque"/>
</style>
<child>
<object class="GtkImage">
<property name="icon-name">view-conceal-symbolic</property>
</object>
</child>
</object> </object>
</child> </child>
</object> </object>

View File

@ -14,7 +14,12 @@ Adw.MessageDialog clipboard_confirmation_window {
default-response: "cancel"; default-response: "cancel";
close-response: "cancel"; close-response: "cancel";
extra-child: ScrolledWindow { extra-child: Overlay {
styles [
"osd"
]
ScrolledWindow text_view_scroll {
width-request: 500; width-request: 500;
height-request: 250; height-request: 250;
@ -26,6 +31,41 @@ Adw.MessageDialog clipboard_confirmation_window {
left-margin: 8; left-margin: 8;
bottom-margin: 8; bottom-margin: 8;
right-margin: 8; right-margin: 8;
styles [
"clipboard-content-view"
]
}
}
[overlay]
Button reveal_button {
visible: false;
halign: end;
valign: start;
margin-end: 12;
margin-top: 12;
Image {
icon-name: "view-reveal-symbolic";
}
}
[overlay]
Button hide_button {
visible: false;
halign: end;
valign: start;
margin-end: 12;
margin-top: 12;
styles [
"opaque"
]
Image {
icon-name: "view-conceal-symbolic";
}
} }
}; };
} }

View File

@ -7,16 +7,21 @@ corresponding .blp file and regenerate this file with blueprint-compiler.
<interface domain="com.mitchellh.ghostty"> <interface domain="com.mitchellh.ghostty">
<requires lib="gtk" version="4.0"/> <requires lib="gtk" version="4.0"/>
<object class="AdwMessageDialog" id="clipboard_confirmation_window"> <object class="AdwMessageDialog" id="clipboard_confirmation_window">
<property name="heading" translatable="yes">Warning: Potentially Unsafe Paste</property> <property name="heading" translatable="true">Warning: Potentially Unsafe Paste</property>
<property name="body" translatable="yes">Pasting this text into the terminal may be dangerous as it looks like some commands may be executed.</property> <property name="body" translatable="true">Pasting this text into the terminal may be dangerous as it looks like some commands may be executed.</property>
<responses> <responses>
<response id="cancel" translatable="yes" appearance="suggested">Cancel</response> <response id="cancel" translatable="true" appearance="suggested">Cancel</response>
<response id="ok" translatable="yes" appearance="destructive">Paste</response> <response id="ok" translatable="true" appearance="destructive">Paste</response>
</responses> </responses>
<property name="default-response">cancel</property> <property name="default-response">cancel</property>
<property name="close-response">cancel</property> <property name="close-response">cancel</property>
<property name="extra-child"> <property name="extra-child">
<object class="GtkScrolledWindow"> <object class="GtkOverlay">
<style>
<class name="osd"/>
</style>
<child>
<object class="GtkScrolledWindow" id="text_view_scroll">
<property name="width-request">500</property> <property name="width-request">500</property>
<property name="height-request">250</property> <property name="height-request">250</property>
<child> <child>
@ -28,6 +33,42 @@ corresponding .blp file and regenerate this file with blueprint-compiler.
<property name="left-margin">8</property> <property name="left-margin">8</property>
<property name="bottom-margin">8</property> <property name="bottom-margin">8</property>
<property name="right-margin">8</property> <property name="right-margin">8</property>
<style>
<class name="clipboard-content-view"/>
</style>
</object>
</child>
</object>
</child>
<child type="overlay">
<object class="GtkButton" id="reveal_button">
<property name="visible">false</property>
<property name="halign">2</property>
<property name="valign">1</property>
<property name="margin-end">12</property>
<property name="margin-top">12</property>
<child>
<object class="GtkImage">
<property name="icon-name">view-reveal-symbolic</property>
</object>
</child>
</object>
</child>
<child type="overlay">
<object class="GtkButton" id="hide_button">
<property name="visible">false</property>
<property name="halign">2</property>
<property name="valign">1</property>
<property name="margin-end">12</property>
<property name="margin-top">12</property>
<style>
<class name="opaque"/>
</style>
<child>
<object class="GtkImage">
<property name="icon-name">view-conceal-symbolic</property>
</object>
</child>
</object> </object>
</child> </child>
</object> </object>

View File

@ -15,6 +15,10 @@ Adw.AlertDialog clipboard_confirmation_window {
close-response: "cancel"; close-response: "cancel";
extra-child: Overlay { extra-child: Overlay {
styles [
"osd"
]
ScrolledWindow text_view_scroll { ScrolledWindow text_view_scroll {
width-request: 500; width-request: 500;
height-request: 250; height-request: 250;
@ -42,10 +46,6 @@ Adw.AlertDialog clipboard_confirmation_window {
margin-end: 12; margin-end: 12;
margin-top: 12; margin-top: 12;
styles [
"destructive-action",
]
Image { Image {
icon-name: "view-reveal-symbolic"; icon-name: "view-reveal-symbolic";
} }
@ -60,7 +60,7 @@ Adw.AlertDialog clipboard_confirmation_window {
margin-top: 12; margin-top: 12;
styles [ styles [
"suggested-action", "opaque"
] ]
Image { Image {

View File

@ -15,6 +15,10 @@ Adw.AlertDialog clipboard_confirmation_window {
close-response: "cancel"; close-response: "cancel";
extra-child: Overlay { extra-child: Overlay {
styles [
"osd"
]
ScrolledWindow text_view_scroll { ScrolledWindow text_view_scroll {
width-request: 500; width-request: 500;
height-request: 250; height-request: 250;
@ -42,10 +46,6 @@ Adw.AlertDialog clipboard_confirmation_window {
margin-end: 12; margin-end: 12;
margin-top: 12; margin-top: 12;
styles [
"destructive-action",
]
Image { Image {
icon-name: "view-reveal-symbolic"; icon-name: "view-reveal-symbolic";
} }
@ -60,7 +60,7 @@ Adw.AlertDialog clipboard_confirmation_window {
margin-top: 12; margin-top: 12;
styles [ styles [
"suggested-action", "opaque"
] ]
Image { Image {

View File

@ -15,6 +15,10 @@ Adw.AlertDialog clipboard_confirmation_window {
close-response: "cancel"; close-response: "cancel";
extra-child: Overlay { extra-child: Overlay {
styles [
"osd"
]
ScrolledWindow text_view_scroll { ScrolledWindow text_view_scroll {
width-request: 500; width-request: 500;
height-request: 250; height-request: 250;
@ -42,10 +46,6 @@ Adw.AlertDialog clipboard_confirmation_window {
margin-end: 12; margin-end: 12;
margin-top: 12; margin-top: 12;
styles [
"destructive-action",
]
Image { Image {
icon-name: "view-reveal-symbolic"; icon-name: "view-reveal-symbolic";
} }
@ -60,7 +60,7 @@ Adw.AlertDialog clipboard_confirmation_window {
margin-top: 12; margin-top: 12;
styles [ styles [
"suggested-action", "opaque"
] ]
Image { Image {