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

fix: workspace applet wayland support #674

Merged
merged 2 commits into from
Feb 19, 2025
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
50 changes: 25 additions & 25 deletions src/panel/applets/workspaces/WindowIcon.vala
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,30 @@

namespace Workspaces {
public const int WORKSPACE_ICON_SIZE = 16;
public const string FALLBACK_ICON_NAME = "image-missing";

public class WindowIcon : Gtk.Button {
private libxfce4windowing.Window window;

public WindowIcon(libxfce4windowing.Window window) {
this.window = window;
public libxfce4windowing.Window window { get; construct; }

construct {
this.set_relief(Gtk.ReliefStyle.NONE);
this.get_style_context().add_class("workspace-icon-button");
this.set_tooltip_text(window.get_name());

Gtk.Image icon = new Gtk.Image.from_gicon(window.get_gicon(), Gtk.IconSize.INVALID);
icon.set_pixel_size(WORKSPACE_ICON_SIZE);
Gtk.Image icon;

// When a window has just been created, its application
// may not be set yet, so default to a generic icon if
// there is no application. It will be set when the
// icon_changed signal is called.
if (this.window.application != null) {
unowned var pixbuf = window.get_icon(WORKSPACE_ICON_SIZE, get_scale_factor());
icon = new Gtk.Image.from_pixbuf(pixbuf);
} else {
icon = new Gtk.Image.from_icon_name(FALLBACK_ICON_NAME, Gtk.IconSize.INVALID);
icon.pixel_size = WORKSPACE_ICON_SIZE;
}

this.add(icon);
icon.show();

Expand All @@ -32,8 +43,10 @@ namespace Workspaces {
});

window.icon_changed.connect(() => {
icon.set_from_gicon(window.get_gicon(), Gtk.IconSize.INVALID);
unowned var pixbuf = window.get_icon(WORKSPACE_ICON_SIZE, get_scale_factor());
icon.set_from_pixbuf(pixbuf);
icon.queue_draw();
Gtk.drag_source_set_icon_pixbuf(this, pixbuf);
});

Gtk.drag_source_set(
Expand All @@ -43,15 +56,17 @@ namespace Workspaces {
Gdk.DragAction.MOVE
);

Gtk.drag_source_set_icon_gicon(this, window.get_gicon());

this.drag_begin.connect(on_drag_begin);
this.drag_end.connect(on_drag_end);
this.drag_data_get.connect(on_drag_data_get);

this.show_all();
}

public WindowIcon(libxfce4windowing.Window window) {
Object(window: window);
}

public override bool button_release_event(Gdk.EventButton event) {
if (event.button != 1) return Gdk.EVENT_STOP;

Expand All @@ -72,22 +87,7 @@ namespace Workspaces {
}

public void on_drag_data_get(Gtk.Widget widget, Gdk.DragContext context, Gtk.SelectionData selection_data, uint target_type, uint time) {
ulong window_xid = (ulong)window.x11_get_xid();
uchar[] buf;
convert_ulong_to_bytes(window_xid, out buf);
selection_data.set(
selection_data.get_target(),
8,
buf
);
}

private void convert_ulong_to_bytes(ulong number, out uchar[] buffer) {
buffer = new uchar[sizeof(ulong)];
for (int i=0; i<sizeof(ulong); i++) {
buffer[i] = (uchar)(number & 0xFF);
number = number >> 8;
}
selection_data.set_text(string.joinv(",", window.get_class_ids()), -1);
}
}
}
9 changes: 5 additions & 4 deletions src/panel/applets/workspaces/WorkspaceItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Workspaces {
const Gtk.TargetEntry[] target_list = {
{ "application/x-wnck-window-id", 0, 0 }
{ "text/plain", 0, 0 }
};

public class WorkspaceItem : Gtk.EventBox {
Expand Down Expand Up @@ -174,12 +174,13 @@ namespace Workspaces {
private void on_drag_data_received(Gtk.Widget widget, Gdk.DragContext context, int x, int y, Gtk.SelectionData selection_data, uint target_type, uint time) {
bool dnd_success = false;

ulong* data = (ulong*)selection_data.get_data();
string? data = selection_data.get_text();

if (data != null) {
try {
foreach (libxfce4windowing.Window window in WorkspacesApplet.xfce_screen.get_windows()) {
if (window.x11_get_xid() == *data) {
string all_class_names = string.joinv(",", window.get_class_ids());
if (all_class_names == data) {
window.move_to_workspace(this.workspace);
dnd_success = true;
break;
Expand All @@ -193,7 +194,7 @@ namespace Workspaces {
Gtk.drag_finish(context, dnd_success, true, time);
}

public void update_windows(List<weak libxfce4windowing.Window> window_list) {
public void update_windows(List<libxfce4windowing.Window> window_list) {
int num_columns = (real_alloc.width - 4) / 20;
int num_rows = (real_alloc.height - 4) / 20;

Expand Down
Loading