Skip to content

Commit

Permalink
Make hover selection more obvious, tie in loading cursor.
Browse files Browse the repository at this point in the history
Applications which may take a while to respond that they have launched may appear to not be doing anything on click otherwise, so we will now use a loading cursor and track launch context changes.

Now use shared launch context, define our cursor setting in unified props to remove code duplicate. Eliminated a bunch of unnecessary setting of cursor.
  • Loading branch information
JoshStrobl committed Oct 11, 2023
1 parent 6283dcb commit 67f9402
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 23 deletions.
9 changes: 7 additions & 2 deletions data/view.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@ limitations under the License.
color: rgba(232, 232, 232, 0.7);
}

.desktop-item-label:not(.selected) {
.desktop-item:not(.selected) .desktop-item-image {
opacity: 0.9;
}

.desktop-item:not(.selected) .desktop-item-label {
color: rgba(232, 232, 232, 0.9);
font-weight: 600;
text-shadow: 0 0 2px rgba(0, 0, 0, 1), 0 0 2px rgba(0, 0, 0, 1);
}

.desktop-item-label.selected {
.desktop-item.selected .desktop-item-label {
color: rgba(240, 240, 240, 1);
font-weight: 600;
text-shadow: 0 0 2px rgba(0, 0, 0, 1), 0 0 2px rgba(0, 0, 0, 1);
}
Expand Down
22 changes: 22 additions & 0 deletions src/budgie_desktop_view.vala
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public class DesktopView : Gtk.ApplicationWindow {
);

shared_props = new UnifiedProps(); // Create shared props
shared_props.cursor_changed.connect((cursor) => {
get_window().set_cursor(cursor);
});
shared_props.thumbnail_size_changed.connect(refresh_icon_sizes); // When our thumbnail size changed, refresh our icons

Gtk.Settings? default_settings = Gtk.Settings.get_default(); // Get the default settings
Expand Down Expand Up @@ -514,6 +517,25 @@ public class DesktopView : Gtk.ApplicationWindow {
default_display = Display.get_default(); // Get the display related to it
shared_props.blocked_cursor = new Cursor.from_name(default_display, "not-allowed");
shared_props.hand_cursor = new Cursor.for_display(default_display, CursorType.ARROW);
shared_props.loading_cursor = new Cursor.from_name(default_display, "progress");

shared_props.launch_context = default_display.get_app_launch_context(); // Get the app launch context for the default display
shared_props.launch_context.set_screen(default_screen); // Set the screen

shared_props.launch_context.launch_started.connect(() => {
shared_props.is_launching = true;
shared_props.current_cursor = shared_props.loading_cursor;
});

shared_props.launch_context.launch_failed.connect(() => {
shared_props.is_launching = false;
shared_props.current_cursor = shared_props.hand_cursor;
});

shared_props.launch_context.launched.connect(() => {
shared_props.is_launching = false;
shared_props.current_cursor = shared_props.hand_cursor;
});

primary_monitor = default_display.get_primary_monitor(); // Get the actual primary monitor for this display

Expand Down
24 changes: 11 additions & 13 deletions src/desktop_item.vala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class DesktopItem : FlowBoxChild {

public DesktopItem() {
Object(); // Create our DesktopItem as a FlowBoxChild
get_style_context().add_class("desktop-item");
expand = true; // Expand when possible
margin = ITEM_MARGIN;
set_no_show_all(true);
Expand Down Expand Up @@ -128,29 +129,25 @@ public class DesktopItem : FlowBoxChild {

// on_enter handles mouse entry
private bool on_enter(EventCrossing event) {
if (event.mode != Gdk.CrossingMode.NORMAL) {
return EVENT_STOP;
}
if (event.mode != Gdk.CrossingMode.NORMAL) return EVENT_STOP;

label.get_style_context().add_class("selected");
get_style_context().add_class("selected");

if (_copying) { // Currently copying
get_window().set_cursor(props.blocked_cursor);
} else { // Not currently copying
get_window().set_cursor(props.hand_cursor);
props.current_cursor = props.blocked_cursor;
}

return EVENT_STOP;
}

// on_leave handles mouse leaving
private bool on_leave(EventCrossing event) {
if (event.mode != Gdk.CrossingMode.NORMAL) {
get_window().set_cursor(null);
return EVENT_STOP;
}
if (event.mode != Gdk.CrossingMode.NORMAL) return EVENT_STOP;

get_style_context().remove_class("selected");

if (!props.is_launching) props.current_cursor = props.hand_cursor;

label.get_style_context().remove_class("selected");
get_window().set_cursor(null);
return EVENT_STOP;
}

Expand Down Expand Up @@ -258,6 +255,7 @@ public class DesktopItem : FlowBoxChild {

if (image == null) { // If we haven't created the Image yet
image = new Image.from_pixbuf(pix); // Load the image from pixbuf
image.get_style_context().add_class("desktop-item-image");
image.margin_bottom = 10;
main_layout.pack_start(image, true, true, 0); // Indicate this is the center widget
} else { // If the Image already exists
Expand Down
12 changes: 5 additions & 7 deletions src/file_item.vala
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,11 @@ public class FileItem : DesktopItem {
// launch will attempt to launch the file.
// This optionally takes in in_terminal indicating to open in the user's default terminal as well as the terminal process name
public void launch(bool in_terminal) {
Gdk.AppLaunchContext launch_context = (Display.get_default()).get_app_launch_context(); // Get the app launch context for the default display
launch_context.set_screen(Screen.get_default()); // Set the screen
launch_context.set_timestamp(CURRENT_TIME);
props.launch_context.set_timestamp(CURRENT_TIME);

if (app_info != null) { // If we got the app info for this
try {
app_info.launch(null, launch_context); // Launch the application
app_info.launch(null, props.launch_context); // Launch the application
} catch (Error e) {
warning("Failed to launch %s: %s", name, e.message);
}
Expand All @@ -205,7 +203,7 @@ public class FileItem : DesktopItem {
if (keyfile != null) { // Have a custom key file
try {
string keyfile_url = keyfile.get_string("Desktop Entry", "URL");
AppInfo.launch_default_for_uri(keyfile_url, launch_context);
AppInfo.launch_default_for_uri(keyfile_url, props.launch_context);
} catch (Error e) {
warning("Failed to launch %s: %s", name, e.message);
}
Expand Down Expand Up @@ -313,9 +311,9 @@ public class FileItem : DesktopItem {
if (file_type == "trash") { // Is trash
List<string> trash_uris = new List<string>();
trash_uris.append("trash:///"); // Open as trash:/// so Nautilus can show us the empty banner
appinfo.launch_uris(trash_uris, launch_context);
appinfo.launch_uris(trash_uris, props.launch_context);
} else {
appinfo.launch(file_list, launch_context); // Launch the file
appinfo.launch(file_list, props.launch_context); // Launch the file
}
} catch (Error e) {
warning("Failed to launch %s: %s", name, e.message);
Expand Down
29 changes: 28 additions & 1 deletion src/unified_props.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,33 @@ public enum ClickPolicyType {
// UnifiedProps contains a multitude of shared properties used for our various item types
public class UnifiedProps : Object {
public HashTable<string, Cancellable?> files_currently_copying; // All files currently being copied
public bool is_launching;

// Shared properties
private GLib.Settings? _settings;
private bool _is_single_click;
private int _max_thumbnail_size;
public FileMenu? file_menu;

private Gdk.Cursor? _previous_cursor;
private Gdk.Cursor? _current_cursor;
public Gdk.Cursor? blocked_cursor;
public Gdk.Cursor? hand_cursor;
public Gdk.Cursor? loading_cursor;

public Gdk.AppLaunchContext? launch_context;
public FileMenu? file_menu;
public IconTheme icon_theme;
public int? icon_size;
public int? s_factor;

public signal void cursor_changed(Gdk.Cursor cursor);
public signal void thumbnail_size_changed();

// Create a new UnifiedProps.
// Doesn't require any initial constructor properties since we want the flexibility of setting these across various parts of the codebase
public UnifiedProps() {
files_currently_copying = new HashTable<string, Cancellable>(str_hash, str_equal); // Create our empty list
is_launching = false;
_is_single_click = true;
_max_thumbnail_size = 10;
}
Expand Down Expand Up @@ -76,6 +85,24 @@ public class UnifiedProps : Object {
}
}

public Gdk.Cursor? current_cursor {
public get {
return _current_cursor;
}

public set {
_previous_cursor = _current_cursor;
_current_cursor = value;
if (_current_cursor != null) cursor_changed(_current_cursor);
}
}

public Gdk.Cursor? previous_cursor {
public get {
return _previous_cursor;
}
}

// is_copying returns if this file is currently copying
public bool is_copying(string file_name) {
return files_currently_copying.contains(file_name);
Expand Down

0 comments on commit 67f9402

Please sign in to comment.