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

View File

@ -1209,7 +1209,13 @@ fn gtkClipboardRead(
error.UnauthorizedPaste,
=> {
// 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});
};
return;
@ -2224,7 +2230,13 @@ fn doPaste(self: *Surface, data: [:0]const u8) void {
error.UnsafePaste,
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});
};
},

View File

@ -14,18 +14,58 @@ Adw.MessageDialog clipboard_confirmation_window {
default-response: "cancel";
close-response: "cancel";
extra-child: ScrolledWindow {
width-request: 500;
height-request: 250;
extra-child: Overlay {
styles [
"osd"
]
TextView text_view {
cursor-visible: false;
editable: false;
monospace: true;
top-margin: 8;
left-margin: 8;
bottom-margin: 8;
right-margin: 8;
ScrolledWindow text_view_scroll {
width-request: 500;
height-request: 250;
TextView text_view {
cursor-visible: false;
editable: false;
monospace: true;
top-margin: 8;
left-margin: 8;
bottom-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,27 +7,68 @@ corresponding .blp file and regenerate this file with blueprint-compiler.
<interface domain="com.mitchellh.ghostty">
<requires lib="gtk" version="4.0"/>
<object class="AdwMessageDialog" id="clipboard_confirmation_window">
<property name="heading" translatable="yes">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="heading" translatable="true">Authorize Clipboard Access</property>
<property name="body" translatable="true">An application is attempting to read from the clipboard. The current clipboard contents are shown below.</property>
<responses>
<response id="cancel" translatable="yes" appearance="suggested">Deny</response>
<response id="ok" translatable="yes" appearance="destructive">Allow</response>
<response id="cancel" translatable="true" appearance="suggested">Deny</response>
<response id="ok" translatable="true" appearance="destructive">Allow</response>
</responses>
<property name="default-response">cancel</property>
<property name="close-response">cancel</property>
<property name="extra-child">
<object class="GtkScrolledWindow">
<property name="width-request">500</property>
<property name="height-request">250</property>
<object class="GtkOverlay">
<style>
<class name="osd"/>
</style>
<child>
<object class="GtkTextView" id="text_view">
<property name="cursor-visible">false</property>
<property name="editable">false</property>
<property name="monospace">true</property>
<property name="top-margin">8</property>
<property name="left-margin">8</property>
<property name="bottom-margin">8</property>
<property name="right-margin">8</property>
<object class="GtkScrolledWindow" id="text_view_scroll">
<property name="width-request">500</property>
<property name="height-request">250</property>
<child>
<object class="GtkTextView" id="text_view">
<property name="cursor-visible">false</property>
<property name="editable">false</property>
<property name="monospace">true</property>
<property name="top-margin">8</property>
<property name="left-margin">8</property>
<property name="bottom-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>
</child>
</object>

View File

@ -14,18 +14,58 @@ Adw.MessageDialog clipboard_confirmation_window {
default-response: "cancel";
close-response: "cancel";
extra-child: ScrolledWindow {
width-request: 500;
height-request: 250;
extra-child: Overlay {
styles [
"osd"
]
TextView text_view {
cursor-visible: false;
editable: false;
monospace: true;
top-margin: 8;
left-margin: 8;
bottom-margin: 8;
right-margin: 8;
ScrolledWindow text_view_scroll {
width-request: 500;
height-request: 250;
TextView text_view {
cursor-visible: false;
editable: false;
monospace: true;
top-margin: 8;
left-margin: 8;
bottom-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,27 +7,68 @@ corresponding .blp file and regenerate this file with blueprint-compiler.
<interface domain="com.mitchellh.ghostty">
<requires lib="gtk" version="4.0"/>
<object class="AdwMessageDialog" id="clipboard_confirmation_window">
<property name="heading" translatable="yes">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="heading" translatable="true">Authorize Clipboard Access</property>
<property name="body" translatable="true">An application is attempting to write to the clipboard. The current clipboard contents are shown below.</property>
<responses>
<response id="cancel" translatable="yes" appearance="suggested">Deny</response>
<response id="ok" translatable="yes" appearance="destructive">Allow</response>
<response id="cancel" translatable="true" appearance="suggested">Deny</response>
<response id="ok" translatable="true" appearance="destructive">Allow</response>
</responses>
<property name="default-response">cancel</property>
<property name="close-response">cancel</property>
<property name="extra-child">
<object class="GtkScrolledWindow">
<property name="width-request">500</property>
<property name="height-request">250</property>
<object class="GtkOverlay">
<style>
<class name="osd"/>
</style>
<child>
<object class="GtkTextView" id="text_view">
<property name="cursor-visible">false</property>
<property name="editable">false</property>
<property name="monospace">true</property>
<property name="top-margin">8</property>
<property name="left-margin">8</property>
<property name="bottom-margin">8</property>
<property name="right-margin">8</property>
<object class="GtkScrolledWindow" id="text_view_scroll">
<property name="width-request">500</property>
<property name="height-request">250</property>
<child>
<object class="GtkTextView" id="text_view">
<property name="cursor-visible">false</property>
<property name="editable">false</property>
<property name="monospace">true</property>
<property name="top-margin">8</property>
<property name="left-margin">8</property>
<property name="bottom-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>
</child>
</object>

View File

@ -14,18 +14,58 @@ Adw.MessageDialog clipboard_confirmation_window {
default-response: "cancel";
close-response: "cancel";
extra-child: ScrolledWindow {
width-request: 500;
height-request: 250;
extra-child: Overlay {
styles [
"osd"
]
TextView text_view {
cursor-visible: false;
editable: false;
monospace: true;
top-margin: 8;
left-margin: 8;
bottom-margin: 8;
right-margin: 8;
ScrolledWindow text_view_scroll {
width-request: 500;
height-request: 250;
TextView text_view {
cursor-visible: false;
editable: false;
monospace: true;
top-margin: 8;
left-margin: 8;
bottom-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,27 +7,68 @@ corresponding .blp file and regenerate this file with blueprint-compiler.
<interface domain="com.mitchellh.ghostty">
<requires lib="gtk" version="4.0"/>
<object class="AdwMessageDialog" id="clipboard_confirmation_window">
<property name="heading" translatable="yes">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="heading" translatable="true">Warning: Potentially Unsafe Paste</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>
<response id="cancel" translatable="yes" appearance="suggested">Cancel</response>
<response id="ok" translatable="yes" appearance="destructive">Paste</response>
<response id="cancel" translatable="true" appearance="suggested">Cancel</response>
<response id="ok" translatable="true" appearance="destructive">Paste</response>
</responses>
<property name="default-response">cancel</property>
<property name="close-response">cancel</property>
<property name="extra-child">
<object class="GtkScrolledWindow">
<property name="width-request">500</property>
<property name="height-request">250</property>
<object class="GtkOverlay">
<style>
<class name="osd"/>
</style>
<child>
<object class="GtkTextView" id="text_view">
<property name="cursor-visible">false</property>
<property name="editable">false</property>
<property name="monospace">true</property>
<property name="top-margin">8</property>
<property name="left-margin">8</property>
<property name="bottom-margin">8</property>
<property name="right-margin">8</property>
<object class="GtkScrolledWindow" id="text_view_scroll">
<property name="width-request">500</property>
<property name="height-request">250</property>
<child>
<object class="GtkTextView" id="text_view">
<property name="cursor-visible">false</property>
<property name="editable">false</property>
<property name="monospace">true</property>
<property name="top-margin">8</property>
<property name="left-margin">8</property>
<property name="bottom-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>
</child>
</object>

View File

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

View File

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

View File

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