FileWidgets: Improve mouse enter/leave identification
This commit is contained in:
parent
7c7910729a
commit
c85945ae26
|
@ -17,16 +17,10 @@ public class FileDefaultWidget : EventBox {
|
||||||
[GtkChild] public EventBox stack_event_box;
|
[GtkChild] public EventBox stack_event_box;
|
||||||
|
|
||||||
private FileTransfer.State state;
|
private FileTransfer.State state;
|
||||||
private bool pointer_inside = false;
|
|
||||||
|
|
||||||
public FileDefaultWidget() {
|
public FileDefaultWidget() {
|
||||||
this.enter_notify_event.connect(on_pointer_entered);
|
this.enter_notify_event.connect(on_pointer_entered);
|
||||||
this.leave_notify_event.connect(on_pointer_left);
|
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) {
|
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) {
|
private bool on_pointer_entered(Gdk.EventCrossing event) {
|
||||||
pointer_inside = true;
|
if (event.detail == Gdk.NotifyType.INFERIOR) return false;
|
||||||
Timeout.add(20, () => {
|
|
||||||
if (pointer_inside) {
|
|
||||||
event.get_window().set_cursor(new Cursor.for_display(Gdk.Display.get_default(), CursorType.HAND2));
|
event.get_window().set_cursor(new Cursor.for_display(Gdk.Display.get_default(), CursorType.HAND2));
|
||||||
content_type_image.opacity = 0.7;
|
content_type_image.opacity = 0.7;
|
||||||
if (state == FileTransfer.State.NOT_STARTED) {
|
if (state == FileTransfer.State.NOT_STARTED) {
|
||||||
image_stack.set_visible_child_name("download_image");
|
image_stack.set_visible_child_name("download_image");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool on_pointer_left(Gdk.EventCrossing event) {
|
private bool on_pointer_left(Gdk.EventCrossing event) {
|
||||||
pointer_inside = false;
|
if (event.detail == Gdk.NotifyType.INFERIOR) return false;
|
||||||
Timeout.add(20, () => {
|
|
||||||
if (!pointer_inside) {
|
|
||||||
event.get_window().set_cursor(new Cursor.for_display(Gdk.Display.get_default(), CursorType.XTERM));
|
event.get_window().set_cursor(new Cursor.for_display(Gdk.Display.get_default(), CursorType.XTERM));
|
||||||
content_type_image.opacity = 0.5;
|
content_type_image.opacity = 0.5;
|
||||||
if (state == FileTransfer.State.NOT_STARTED) {
|
if (state == FileTransfer.State.NOT_STARTED) {
|
||||||
image_stack.set_visible_child_name("content_type_image");
|
image_stack.set_visible_child_name("content_type_image");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ public class FileImageWidget : EventBox {
|
||||||
private ScalingImage image;
|
private ScalingImage image;
|
||||||
FileDefaultWidget file_default_widget;
|
FileDefaultWidget file_default_widget;
|
||||||
FileDefaultWidgetController file_default_widget_controller;
|
FileDefaultWidgetController file_default_widget_controller;
|
||||||
private bool pointer_inside = false;
|
|
||||||
|
|
||||||
public FileImageWidget() {
|
public FileImageWidget() {
|
||||||
this.halign = Align.START;
|
this.halign = Align.START;
|
||||||
|
@ -60,25 +59,17 @@ public class FileImageWidget : EventBox {
|
||||||
overlay.add(image);
|
overlay.add(image);
|
||||||
overlay.add_overlay(file_default_widget);
|
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;
|
file_default_widget.visible = true;
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
this.leave_notify_event.connect(() => {
|
this.leave_notify_event.connect((event) => {
|
||||||
pointer_inside = false;
|
if (event.detail == Gdk.NotifyType.INFERIOR) return false;
|
||||||
Timeout.add(20, () => {
|
|
||||||
if (!pointer_inside) {
|
|
||||||
file_default_widget.visible = false;
|
file_default_widget.visible = false;
|
||||||
}
|
|
||||||
return false;
|
return 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);
|
this.add(overlay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue