Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: port to Wayland #33

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ gnome_stack = '>= 3.24.0'
dep_glib = dependency('glib-2.0', version: glib_dep)
dep_gio = dependency('gio-unix-2.0', version: glib_dep)
dep_gdk = dependency('gdk-3.0', version: gnome_stack)
dep_gdk_x11 = dependency('gdk-x11-3.0', version: gnome_stack)
dep_gtk = dependency('gtk+-3.0', version: gnome_stack)
dep_vala = dependency('vapigen', version: '>= 0.48.0')
dep_gtk_layer_shell = dependency('gtk-layer-shell-0', version: '>= 0.8.0')
dep_xfce4windowing = dependency('libxfce4windowing-0', version: '>= 4.19.7')

# Make gettext work
add_global_arguments('-DGETTEXT_PACKAGE="budgie-desktop-view"', language: 'c')
Expand Down
65 changes: 26 additions & 39 deletions src/budgie_desktop_view.vala
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public const string[] SUPPORTED_TERMINALS = {
};

public class DesktopView : Gtk.ApplicationWindow {
Screen default_screen;
Display default_display;
Monitor primary_monitor;
libxfce4windowing.Screen default_screen;
Gdk.Display default_display;
libxfce4windowing.Monitor? primary_monitor;
Rectangle? primary_monitor_geo = null;
UnifiedProps shared_props;
Raven? raven = null;
Expand Down Expand Up @@ -89,6 +89,16 @@ public class DesktopView : Gtk.ApplicationWindow {
type_hint: Gdk.WindowTypeHint.DESKTOP
);

GtkLayerShell.init_for_window(this);
GtkLayerShell.set_layer(this, GtkLayerShell.Layer.BACKGROUND);
GtkLayerShell.set_anchor(
this,
GtkLayerShell.Edge.TOP | GtkLayerShell.Edge.LEFT,
true
);
GtkLayerShell.set_keyboard_mode(this, GtkLayerShell.KeyboardMode.ON_DEMAND);
GtkLayerShell.try_force_commit(this);

shared_props = new UnifiedProps(); // Create shared props
shared_props.cursor_changed.connect((cursor) => {
get_window().set_cursor(cursor);
Expand Down Expand Up @@ -143,8 +153,6 @@ public class DesktopView : Gtk.ApplicationWindow {
}

// Window settings
set_keep_below(true); // Stay below other windows
set_position(WindowPosition.CENTER); // Don't account for anything like current pouse position
show_menubar = false;

desktop_menu = new DesktopMenu(); // Create our new desktop menu
Expand All @@ -160,11 +168,7 @@ public class DesktopView : Gtk.ApplicationWindow {

get_display_geo(); // Set our geo

default_screen.composited_changed.connect(set_window_transparent);
default_screen.monitors_changed.connect(on_resolution_change);
default_screen.size_changed.connect(on_resolution_change);

setup_root_window_event_handler();

add(flow);

Expand Down Expand Up @@ -480,7 +484,7 @@ public class DesktopView : Gtk.ApplicationWindow {
// get_all_desktop_files will get all the files in our Desktop folder and generate items for them
private void get_all_desktop_files() {
var c = new Cancellable(); // Create a new cancellable stack
FileEnumerator? desktop_file_enumerator = null;
FileEnumerator? desktop_file_enumerator = null;

try {
desktop_file_enumerator = desktop_file.enumerate_children("standard::*,standard::display-name", FileQueryInfoFlags.NONE, c);
Expand Down Expand Up @@ -511,16 +515,16 @@ public class DesktopView : Gtk.ApplicationWindow {

// get_display_geo will get or update our primary monitor workarea
private void get_display_geo() {
default_screen = Screen.get_default(); // Get our current default Screen
screen = default_screen;
default_screen = libxfce4windowing.Screen.get_default(); // Get our current default Screen
primary_monitor = default_screen.get_primary_monitor();

default_display = Display.get_default(); // Get the display related to it
default_display = default_screen.gdk_screen.get_display(); // 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.set_screen(default_screen.gdk_screen); // Set the screen

shared_props.launch_context.launch_started.connect(() => {
shared_props.is_launching = true;
Expand All @@ -537,11 +541,9 @@ public class DesktopView : Gtk.ApplicationWindow {
shared_props.current_cursor = shared_props.hand_cursor;
});

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

primary_monitor_geo = primary_monitor.get_workarea(); // Get the working area of this monitor
shared_props.s_factor = primary_monitor.get_scale_factor(); // Get the current scaling factor
update_window_position();
shared_props.s_factor = primary_monitor.get_scale(); // Get the current scaling factor
update_window_sizing();
}

// get_mount_uuid will get a mount UUID and return it
Expand Down Expand Up @@ -617,8 +619,8 @@ public class DesktopView : Gtk.ApplicationWindow {
} else if (event.button == 3) { // Right click
dismiss_raven(); // Dismiss raven

desktop_menu.place_on_monitor(primary_monitor); // Ensure menu is on primary monitor
desktop_menu.set_screen(default_screen); // Ensure menu is on our screen
desktop_menu.place_on_monitor(primary_monitor.gdk_monitor); // Ensure menu is on primary monitor
desktop_menu.set_screen(default_screen.gdk_screen); // Ensure menu is on our screen
desktop_menu.popup_at_pointer(event); // Popup where our mouse is

return Gdk.EVENT_STOP;
Expand Down Expand Up @@ -958,7 +960,7 @@ public class DesktopView : Gtk.ApplicationWindow {

if (visible_setting) {
show();
update_window_position();
update_window_sizing();
} else {
hide();
}
Expand Down Expand Up @@ -1016,22 +1018,6 @@ public class DesktopView : Gtk.ApplicationWindow {
enforce_content_limit(); // Update our flowbox content limit based on icon / item sizing
}

public void setup_root_window_event_handler() {
Gdk.Window root_window = default_screen.get_root_window();
root_window.set_events(EventMask.ALL_EVENTS_MASK);

root_window.add_filter((xevent, e) => {
X.Event xev = *((X.Event*) xevent);

if (xev.type != X.EventType.PropertyNotify) return FilterReturn.CONTINUE;
if (xev.xproperty.atom == Gdk.X11.get_xatom_by_name("_NET_WORKAREA")) {
get_display_geo();
}

return FilterReturn.CONTINUE;
});
}

// create_fileitem_sorter will create our fileitem sorter
// Folders should go before files, with the values of each being collated
private void create_fileitem_sorter() {
Expand Down Expand Up @@ -1108,9 +1094,10 @@ public class DesktopView : Gtk.ApplicationWindow {
}
}

private void update_window_position() {
private void update_window_sizing() {
set_default_size(primary_monitor_geo.width, primary_monitor_geo.height);
flow.set_size_request(primary_monitor_geo.width, primary_monitor_geo.height);
move(primary_monitor_geo.x, primary_monitor_geo.y); // Move the window to the x/y of our primary monitor
get_item_size(); // Update desired item spacing
enforce_content_limit();
}
}
4 changes: 2 additions & 2 deletions src/desktop_item.vala
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,14 @@ public class DesktopItem : FlowBoxChild {

icon = ico; // Set the icon

IconInfo? icon_info = props.icon_theme.lookup_by_gicon_for_scale(icon, props.icon_size, props.s_factor, IconLookupFlags.USE_BUILTIN & IconLookupFlags.GENERIC_FALLBACK);
IconInfo? icon_info = props.icon_theme.lookup_by_gicon_for_scale(icon, props.icon_size, (int) props.s_factor, IconLookupFlags.USE_BUILTIN & IconLookupFlags.GENERIC_FALLBACK);
set_icon_from_iconinfo(icon_info);
}

// set_icon_from_name is responsible for setting our icon based on an icon name
public void set_icon_from_name(string icon_name) throws Error {
try {
Pixbuf? pix = props.icon_theme.load_icon_for_scale(icon_name, props.icon_size, props.s_factor, IconLookupFlags.GENERIC_FALLBACK);
Pixbuf? pix = props.icon_theme.load_icon_for_scale(icon_name, props.icon_size, (int) props.s_factor, IconLookupFlags.GENERIC_FALLBACK);
set_image_pixbuf(pix);
} catch (Error e) {
throw e;
Expand Down
6 changes: 4 additions & 2 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ desktop_view_sources = [

desktop_view_deps = [
dep_gdk,
dep_gdk_x11,
dep_glib,
dep_gio,
dep_gtk
dep_gtk,
dep_gtk_layer_shell,
dep_xfce4windowing
]

c_flags = []
Expand All @@ -31,6 +32,7 @@ executable(
'--pkg', 'gio-unix-2.0',
'--pkg', 'gtk+-3.0',
'--target-glib=2.64',
'--vapidir', join_paths(meson.source_root(), 'vapi'),
],
install: true,
install_dir: join_paths(get_option('prefix'), get_option('bindir')),
Expand Down
2 changes: 1 addition & 1 deletion src/unified_props.vala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class UnifiedProps : Object {
public FileMenu? file_menu;
public IconTheme icon_theme;
public int? icon_size;
public int? s_factor;
public uint? s_factor;

public signal void cursor_changed(Gdk.Cursor cursor);
public signal void thumbnail_size_changed();
Expand Down
13 changes: 13 additions & 0 deletions vapi/libxfce4windowing-0-custom.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace libxfce4windowing {
[CCode (cheader_filename = "libxfce4windowing/libxfce4windowing.h", cname = "XfwApplication", type_id = "xfw_application_get_type ()")]
public abstract class Application : GLib.Object {
[CCode (cname = "xfw_application_get_instance")]
public unowned libxfce4windowing.ApplicationInstance? get_instance (libxfce4windowing.Window window);
}

[CCode (cheader_filename = "libxfce4windowing/libxfce4windowing.h", cname = "XfwWorkspace", type_id = "xfw_workspace_get_type ()")]
public interface Workspace : GLib.Object {
[CCode (cname = "xfw_workspace_assign_to_workspace_group")]
public bool assign_to_workspace_group (libxfce4windowing.WorkspaceGroup group) throws GLib.Error;
}
}
4 changes: 4 additions & 0 deletions vapi/libxfce4windowing-0.deps
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
gdk-3.0
glib-2.0
gtk+-3.0
libwnck-3.0
Loading
Loading