Skip to content

Commit 22c6c8b

Browse files
committed
Add url_status
1 parent 6c3e0a4 commit 22c6c8b

File tree

3 files changed

+83
-37
lines changed

3 files changed

+83
-37
lines changed

data/resources/ui/window.blp

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -80,37 +80,54 @@ template GeopardWindow: Adw.ApplicationWindow {
8080
text: bind GeopardWindow.progress;
8181
}
8282
[overlay]
83-
Gtk.Revealer bottom_bar_revealer {
84-
transition-type: slide_up;
83+
Gtk.Box {
84+
orientation: vertical;
8585
valign: end;
86-
[child]
87-
Adw.HeaderBar bottom_bar {
88-
show-end-title-buttons: false;
89-
show-start-title-buttons: false;
90-
[start]
91-
Gtk.Button {
92-
icon-name: "go-previous-symbolic";
93-
action-name: "win.previous";
86+
Gtk.Box url_status_box {
87+
styles ["background"]
88+
Gtk.Label url_status {
89+
xalign: 0.0;
90+
halign: start;
91+
wrap: true;
92+
wrap-mode: word_char;
93+
margin-top: 6;
94+
margin-bottom: 6;
95+
margin-start: 6;
96+
margin-end: 6;
9497
}
95-
[start]
96-
Gtk.Button {
97-
icon-name: "go-next-symbolic";
98-
action-name: "win.next";
99-
}
100-
[title]
101-
Gtk.Button {
102-
icon-name: "system-search-symbolic";
103-
action-name: "win.focus-url-bar";
104-
}
105-
[end]
106-
Gtk.MenuButton {
107-
icon-name: "open-menu";
108-
menu-model: primary_menu;
109-
}
110-
[end]
111-
Gtk.Button {
112-
icon-name: "tab-new-symbolic";
113-
action-name: "win.new-tab";
98+
}
99+
Gtk.Revealer bottom_bar_revealer {
100+
transition-type: slide_up;
101+
valign: end;
102+
[child]
103+
Adw.HeaderBar bottom_bar {
104+
show-end-title-buttons: false;
105+
show-start-title-buttons: false;
106+
[start]
107+
Gtk.Button {
108+
icon-name: "go-previous-symbolic";
109+
action-name: "win.previous";
110+
}
111+
[start]
112+
Gtk.Button {
113+
icon-name: "go-next-symbolic";
114+
action-name: "win.next";
115+
}
116+
[title]
117+
Gtk.Button {
118+
icon-name: "system-search-symbolic";
119+
action-name: "win.focus-url-bar";
120+
}
121+
[end]
122+
Gtk.MenuButton {
123+
icon-name: "open-menu";
124+
menu-model: primary_menu;
125+
}
126+
[end]
127+
Gtk.Button {
128+
icon-name: "tab-new-symbolic";
129+
action-name: "win.new-tab";
130+
}
114131
}
115132
}
116133
}

src/widgets/tab.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ pub mod imp {
7272
pub(crate) title: RefCell<String>,
7373
#[property(get)]
7474
pub(crate) url: RefCell<String>,
75+
#[property(get)]
76+
pub(crate) hover_url: RefCell<String>,
7577
}
7678

7779
#[glib::object_subclass]
@@ -203,15 +205,23 @@ impl Tab {
203205
let gemini_text_ext = imp.gemini_text_ext.borrow();
204206
let gemini_text_ext = gemini_text_ext.as_ref().unwrap();
205207
let link = Self::extract_linkhandler(gemini_text_ext, x, y);
206-
match link {
207-
Ok(_) => {
208-
gemini_text_ext
209-
.text_view
210-
.set_cursor_from_name(Some("pointer"));
211-
}
212-
Err(_) => {
213-
gemini_text_ext.text_view.set_cursor_from_name(Some("text"));
208+
209+
let link_ref = link.as_ref().map(|x| x.as_ref()).unwrap_or("");
210+
211+
// May need optimization. Comparing two strings for each motion event is expensive
212+
if *imp.hover_url.borrow() != link_ref {
213+
match link_ref {
214+
"" => {
215+
gemini_text_ext.text_view.set_cursor_from_name(Some("text"));
216+
}
217+
_ => {
218+
gemini_text_ext
219+
.text_view
220+
.set_cursor_from_name(Some("pointer"));
221+
}
214222
}
223+
imp.hover_url.replace(link.unwrap_or_default());
224+
self.notify("hover-url");
215225
}
216226

217227
Ok(())

src/widgets/window.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ pub mod imp {
4343
#[template_child]
4444
pub(crate) bottom_bar_revealer: TemplateChild<gtk::Revealer>,
4545
#[template_child]
46+
pub(crate) url_status: TemplateChild<gtk::Label>,
47+
#[template_child]
48+
pub(crate) url_status_box: TemplateChild<gtk::Box>,
49+
#[template_child]
4650
pub(crate) header_small: TemplateChild<gtk::WindowHandle>,
4751
#[template_child]
4852
pub(crate) squeezer: TemplateChild<adw::Squeezer>,
@@ -302,6 +306,13 @@ impl Window {
302306
this.set_special_color_from_hash();
303307
}),
304308
);
309+
310+
let ctrl = gtk::EventControllerMotion::new();
311+
imp.url_status_box.add_controller(&ctrl);
312+
let url_status_box_clone = imp.url_status_box.clone();
313+
ctrl.connect_motion(move |_, _, _| {
314+
url_status_box_clone.set_visible(false);
315+
});
305316
}
306317
fn setup_zoom_popover_item(&self) {
307318
let imp = self.imp();
@@ -390,6 +401,14 @@ impl Window {
390401
Some(res.to_value())
391402
})
392403
.build(),
404+
tab.bind_property("hover-url", &*imp.url_status, "label")
405+
.build(),
406+
tab.bind_property("hover-url", &*imp.url_status_box, "visible")
407+
.transform_to(|_, v| {
408+
let v: &str = v.get().unwrap();
409+
Some((!v.is_empty()).to_value())
410+
})
411+
.build(),
393412
]);
394413
};
395414
}

0 commit comments

Comments
 (0)