Skip to content

Commit

Permalink
Straight conversion of screenshot code from mutter to wayland
Browse files Browse the repository at this point in the history
The budgie-wm elements have been moved to the power dialog - i.e.
keeping the separate of daemon windows vs screencapture which
cannot work in the same process.
  • Loading branch information
fossfreedom committed Jan 26, 2025
1 parent b015e58 commit 8980c74
Show file tree
Hide file tree
Showing 6 changed files with 451 additions and 21 deletions.
89 changes: 69 additions & 20 deletions src/daemon/screenshot.vala
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ namespace BudgieScr {
public abstract async void Screenshot(bool include_cursor, bool flash, string filename, out bool success, out string filename_used) throws Error;
public abstract async void ScreenshotWindow(bool include_frame, bool include_cursor, bool flash, string filename,
out bool success, out string filename_used) throws Error;
public abstract bool SupportScreenshotWindow() throws Error;
}

class MakeScreenshot {
Expand All @@ -166,7 +167,7 @@ namespace BudgieScr {
CurrentState windowstate;
static ScreenshotClient? client = null;

public MakeScreenshot(int[]? area) {
private static void MakeClientConnection() {
if (client == null) {
try {
client = GLib.Bus.get_proxy_sync(BusType.SESSION, "org.buddiesofbudgie.BudgieScreenshot", "/org/buddiesofbudgie/Screenshot");
Expand All @@ -175,6 +176,22 @@ namespace BudgieScr {
client = null;
}
}
}

public static bool ScreenshotWindowSupport() {
MakeClientConnection();

try {
return client.SupportScreenshotWindow();
}
catch {
warning("Unknown Screenshot Window support");
return false;
}
}

public MakeScreenshot(int[]? area) {
MakeClientConnection();

windowstate = new CurrentState();
this.area = area;
Expand Down Expand Up @@ -327,6 +344,16 @@ namespace BudgieScr {
private unowned Gtk.Switch? screenshotcapturesoundswitch;

public ScreenshotHomeWindow() {
GtkLayerShell.init_for_window(this);
GtkLayerShell.set_layer(this, GtkLayerShell.Layer.TOP);
var primary_monitor = libxfce4windowing.Screen.get_default().get_primary_monitor();
GtkLayerShell.set_monitor(this, primary_monitor.get_gdk_monitor());
GtkLayerShell.set_anchor(this, GtkLayerShell.Edge.TOP, false);
GtkLayerShell.set_anchor(this, GtkLayerShell.Edge.LEFT, false);
GtkLayerShell.set_keyboard_mode(this, GtkLayerShell.KeyboardMode.ON_DEMAND);

this.set_decorated(true);

windowstate = new CurrentState();
this.set_startup_id("org.buddiesofbudgie.BudgieScreenshot");
this.set_title(_("Budgie Screenshot"));
Expand Down Expand Up @@ -357,7 +384,7 @@ namespace BudgieScr {
topbar = new Gtk.HeaderBar();
topbar.show_close_button = true;
this.set_titlebar(topbar);
this.set_keep_above(true);
//this.set_keep_above(true);

/*
* left or right windowbuttons, that's the question when
Expand Down Expand Up @@ -401,6 +428,7 @@ namespace BudgieScr {
return false;
});
});

this.show_all();
}

Expand Down Expand Up @@ -432,12 +460,14 @@ namespace BudgieScr {
Gtk.Popover newpopover = new Gtk.Popover(b);
Grid popovergrid = new Gtk.Grid();
set_margins(popovergrid, 15, 15, 15, 15);
Label[] shortcutnames = {
// Translators: be as brief as possible; popovers ar cut off if broader than the window
new Label(_("Screenshot entire screen") + ":\t"),
new Label(_("Screenshot active window") + ":\t"),
new Label(_("Screenshot selected area") + ":\t"),
};
bool window_support = MakeScreenshot.ScreenshotWindowSupport();
Label[] shortcutnames = {};
// Translators: be as brief as possible; popovers are cut off if broader than the window
shortcutnames += new Label(_("Screenshot entire screen") + ":\t");
if (window_support) {
shortcutnames += new Label(_("Screenshot active window") + ":\t");
}
shortcutnames += new Label(_("Screenshot selected area") + ":\t");

shortcutlabels = {};
// Shortcuts is about -keyboard- shortcuts
Expand Down Expand Up @@ -542,16 +572,20 @@ namespace BudgieScr {
string[] mode_options = {"Screen", "Window", "Selection"}; // don't translate, internal use
int active = find_stringindex(mode, mode_options);

bool window_support = MakeScreenshot.ScreenshotWindowSupport();
// translate! These are the interface names
string[] areabuttons_labels = {
_("Screen"), _("Window"), _("Selection")
};
string[] areabuttons_labels = {};
string[] icon_names = {};
areabuttons_labels += _("Screen");
icon_names += "selectscreen-symbolic";

if (window_support) {
areabuttons_labels += _("Window");
icon_names += "selectwindow-symbolic";
}

string[] icon_names = {
"selectscreen-symbolic",
"selectwindow-symbolic",
"selectselection-symbolic"
};
areabuttons_labels += _("Selection");
icon_names += "selectselection-symbolic";

int i = 0;
ToggleButton[] selectbuttons = {};
Expand Down Expand Up @@ -595,7 +629,13 @@ namespace BudgieScr {
}

private void select_action(ToggleButton b, ToggleButton[] btns) {
string[] selectmodes = {"Screen", "Window", "Selection"};
string[] selectmodes = {};
bool window_support = MakeScreenshot.ScreenshotWindowSupport();
selectmodes += "Screen";
if (window_support) {
selectmodes += "Window";
}
selectmodes += "Selection";
int i = 0;

foreach (ToggleButton bt in btns) {
Expand Down Expand Up @@ -840,6 +880,16 @@ namespace BudgieScr {
}

public AfterShotWindow() {
GtkLayerShell.init_for_window(this);
GtkLayerShell.set_layer(this, GtkLayerShell.Layer.TOP);
var primary_monitor = libxfce4windowing.Screen.get_default().get_primary_monitor();
GtkLayerShell.set_monitor(this, primary_monitor.get_gdk_monitor());
GtkLayerShell.set_anchor(this, GtkLayerShell.Edge.TOP, false);
GtkLayerShell.set_anchor(this, GtkLayerShell.Edge.LEFT, false);
GtkLayerShell.set_keyboard_mode(this, GtkLayerShell.KeyboardMode.ON_DEMAND);

this.set_decorated(true);

this.set_startup_id("org.buddiesofbudgie.BudgieScreenshot");
this.set_title(_("Budgie Screenshot"));
this.set_wmclass("org.buddiesofbudgie.BudgieScreenshot", "org.buddiesofbudgie.BudgieScreenshot");
Expand Down Expand Up @@ -1291,9 +1341,8 @@ namespace BudgieScr {

private int get_scaling() {
// not very sophisticated, but for now, we'll assume one scale
Gdk.Monitor gdkmon = Gdk.Display.get_default().get_monitor(0);
int curr_scale = gdkmon.get_scale_factor();

var monitor = libxfce4windowing.Screen.get_default().get_primary_monitor();
int curr_scale = (int)monitor.get_scale();
return curr_scale;
}

Expand Down
2 changes: 1 addition & 1 deletion src/daemon/screenshot_main.vala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Budgie {

const OptionEntry[] options = {
{ "interactive", 'i', 0, OptionArg.NONE, ref interactive, "Interactively set options" },
{ "window", 'w', 0, OptionArg.NONE, ref window, "Grab a window instead of the entire display" },
{ "window", 'w', 0, OptionArg.NONE, ref window, "Grab a window instead of the entire display. This capability only works for compatible window managers." },
{ "area", 'a', 0, OptionArg.NONE, ref area, "Grab an area of the display instead of the entire display" },
{ null }
};
Expand Down
5 changes: 5 additions & 0 deletions src/dialogs/power/application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace Budgie {

private ShellShim? shim;

private ScreenshotManager? screenshot_manager;

public PowerApplication() {
Object(application_id: "org.buddiesofbudgie.PowerDialog", flags: 0);

Expand All @@ -32,6 +34,9 @@ namespace Budgie {
*/
shim = new ShellShim();
shim.serve();

screenshot_manager = new ScreenshotManager();
screenshot_manager.serve();
}

public override void activate() {
Expand Down
1 change: 1 addition & 0 deletions src/dialogs/power/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ powerdialog_sources = [
'dialog_button.vala',
'main.vala',
'shim.vala',
'screenshot.vala',
'window.vala'
]

Expand Down
Loading

0 comments on commit 8980c74

Please sign in to comment.