mirror of
https://github.com/TakeV-Lambda/dino.git
synced 2024-11-22 06:54:29 +00:00
FileWidgets: Improve mouse enter/leave identification
This commit is contained in:
parent
7c7910729a
commit
c85945ae26
2 changed files with 19 additions and 42 deletions
|
@ -17,16 +17,10 @@ public class FileDefaultWidget : EventBox {
|
|||
[GtkChild] public EventBox stack_event_box;
|
||||
|
||||
private FileTransfer.State state;
|
||||
private bool pointer_inside = false;
|
||||
|
||||
public FileDefaultWidget() {
|
||||
this.enter_notify_event.connect(on_pointer_entered);
|
||||
this.leave_notify_event.connect(on_pointer_left);
|
||||
|
||||
stack_event_box.enter_notify_event.connect((event) => { pointer_inside = true; return false; });
|
||||
mime_label.enter_notify_event.connect((event) => { pointer_inside = true; return false; });
|
||||
stack_event_box.leave_notify_event.connect((event) => { pointer_inside = true; return false; });
|
||||
mime_label.leave_notify_event.connect((event) => { pointer_inside = true; return false; });
|
||||
}
|
||||
|
||||
public void update_file_info(string? mime_type, FileTransfer.State state, long size) {
|
||||
|
@ -66,32 +60,24 @@ public class FileDefaultWidget : EventBox {
|
|||
}
|
||||
|
||||
private bool on_pointer_entered(Gdk.EventCrossing event) {
|
||||
pointer_inside = true;
|
||||
Timeout.add(20, () => {
|
||||
if (pointer_inside) {
|
||||
event.get_window().set_cursor(new Cursor.for_display(Gdk.Display.get_default(), CursorType.HAND2));
|
||||
content_type_image.opacity = 0.7;
|
||||
if (state == FileTransfer.State.NOT_STARTED) {
|
||||
image_stack.set_visible_child_name("download_image");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
if (event.detail == Gdk.NotifyType.INFERIOR) return false;
|
||||
|
||||
event.get_window().set_cursor(new Cursor.for_display(Gdk.Display.get_default(), CursorType.HAND2));
|
||||
content_type_image.opacity = 0.7;
|
||||
if (state == FileTransfer.State.NOT_STARTED) {
|
||||
image_stack.set_visible_child_name("download_image");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool on_pointer_left(Gdk.EventCrossing event) {
|
||||
pointer_inside = false;
|
||||
Timeout.add(20, () => {
|
||||
if (!pointer_inside) {
|
||||
event.get_window().set_cursor(new Cursor.for_display(Gdk.Display.get_default(), CursorType.XTERM));
|
||||
content_type_image.opacity = 0.5;
|
||||
if (state == FileTransfer.State.NOT_STARTED) {
|
||||
image_stack.set_visible_child_name("content_type_image");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
if (event.detail == Gdk.NotifyType.INFERIOR) return false;
|
||||
|
||||
event.get_window().set_cursor(new Cursor.for_display(Gdk.Display.get_default(), CursorType.XTERM));
|
||||
content_type_image.opacity = 0.5;
|
||||
if (state == FileTransfer.State.NOT_STARTED) {
|
||||
image_stack.set_visible_child_name("content_type_image");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ public class FileImageWidget : EventBox {
|
|||
private ScalingImage image;
|
||||
FileDefaultWidget file_default_widget;
|
||||
FileDefaultWidgetController file_default_widget_controller;
|
||||
private bool pointer_inside = false;
|
||||
|
||||
public FileImageWidget() {
|
||||
this.halign = Align.START;
|
||||
|
@ -60,25 +59,17 @@ public class FileImageWidget : EventBox {
|
|||
overlay.add(image);
|
||||
overlay.add_overlay(file_default_widget);
|
||||
|
||||
this.enter_notify_event.connect(() => {
|
||||
this.enter_notify_event.connect((event) => {
|
||||
if (event.detail == Gdk.NotifyType.INFERIOR) return false;
|
||||
file_default_widget.visible = true;
|
||||
return false;
|
||||
});
|
||||
this.leave_notify_event.connect(() => {
|
||||
pointer_inside = false;
|
||||
Timeout.add(20, () => {
|
||||
if (!pointer_inside) {
|
||||
file_default_widget.visible = false;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
this.leave_notify_event.connect((event) => {
|
||||
if (event.detail == Gdk.NotifyType.INFERIOR) return false;
|
||||
file_default_widget.visible = false;
|
||||
return false;
|
||||
});
|
||||
|
||||
file_default_widget.enter_notify_event.connect(() => { pointer_inside = true; return false; });
|
||||
file_default_widget.leave_notify_event.connect(() => { pointer_inside = true; return false; });
|
||||
|
||||
this.add(overlay);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue