Skip to content

Commit

Permalink
Make the labels inside gtk3 message dialog selectable (#93)
Browse files Browse the repository at this point in the history
* Make the labels inside gtk3 message dialog selectable

* backend/gtk3: Check if child is label before setting it selectable
  • Loading branch information
crumblingstatue authored Nov 30, 2022
1 parent 1646d5a commit 5b59f47
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/backend/gtk3/message_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ impl GtkMessageDialog {
title.as_ptr(),
) as *mut gtk_sys::GtkDialog;

set_child_labels_selectable(dialog);
// Also set the window title, otherwise it would be empty
gtk_sys::gtk_window_set_title(dialog as _, title.as_ptr());

Expand Down Expand Up @@ -89,6 +90,23 @@ impl GtkMessageDialog {
}
}

unsafe fn is_label(type_instance: *const gobject_sys::GTypeInstance) -> bool {
(*(*type_instance).g_class).g_type == gtk_sys::gtk_label_get_type()
}

/// Sets the child labels of a widget selectable
unsafe fn set_child_labels_selectable(dialog: *mut gtk_sys::GtkDialog) {
let area = gtk_sys::gtk_message_dialog_get_message_area(dialog as _);
let mut children = gtk_sys::gtk_container_get_children(area as _);
while !children.is_null() {
let child = (*children).data;
if is_label(child as _) {
gtk_sys::gtk_label_set_selectable(child as _, 1);
}
children = (*children).next;
}
}

impl Drop for GtkMessageDialog {
fn drop(&mut self) {
unsafe {
Expand Down

0 comments on commit 5b59f47

Please sign in to comment.