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

Implement color picking #12

Merged
merged 30 commits into from Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
873fe90
Add handle_pick_color placeholder
Nov 23, 2023
584f0c3
Add partial color picking implementation
Nov 23, 2023
9726c9a
Attempt to use gpick for color picking
Nov 24, 2023
28b3fea
Fix handle type
Nov 24, 2023
b89ebaa
Remove nonexistent handle properties
Nov 24, 2023
981e98b
Add color response handling
Nov 24, 2023
6933472
Enable PickColor method
Nov 24, 2023
e94cdbd
Add colors to ScreenshotHandle
Nov 24, 2023
04f58f7
Switch to generic color picker
Nov 24, 2023
fd3185c
Fix picker finished function refernce
Nov 24, 2023
abc31e1
Add picker output interpretation/unpacking
Nov 24, 2023
aeeecbe
Fix typo
Nov 24, 2023
3a19e0d
Try to get picker output
Nov 24, 2023
5faf7d5
Attempt to make sense of GVariants
Nov 24, 2023
ed37f62
Parse picker output as GVariant
Nov 24, 2023
7609dbb
Properly declare variant type
Nov 24, 2023
c14271e
Attempt to get by without GVariants
Nov 24, 2023
4e400b8
Fix typos
Nov 24, 2023
afc16e4
Remove things that aren't working
Nov 24, 2023
991cd6f
Add an empty stock response
Nov 24, 2023
f4afec1
Use array GVariant
Nov 25, 2023
d08f5a5
Use integers for colors
Nov 25, 2023
585ab9f
Use doubles, but divide by 255.0
Nov 25, 2023
ba95a17
Match types and names with XML spec
Nov 25, 2023
2aef84d
Fix all the things
Nov 25, 2023
ff7c88c
Clean up whitespace
Nov 25, 2023
81ff15e
Replace color picking system with cinnamon-based mockup
Nov 28, 2023
0f9fcc4
Pass expected number of args to ..call_pick_color
Nov 28, 2023
38e2658
Fix expected args in ..pick_done
Nov 28, 2023
c927d75
screenshot: Fix connection with cinnamon, finish color-picker support
mtwebster Nov 29, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

The interface used to capture pictures of the screen contents.
-->
<interface name="org.cinnamon.Screenshot">
<interface name="org.gnome.Shell.Screenshot">

<!--
Screenshot:
Expand Down Expand Up @@ -123,9 +123,9 @@
<arg type="i" direction="out" name="width"/>
<arg type="i" direction="out" name="height"/>
</method>
<!--

<method name="PickColor">
<arg type="a{sv}" direction="out" name="result"/>
</method> -->
</method>
</interface>
</node>
2 changes: 1 addition & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ built_sources = gnome.gdbus_codegen(
desktop_dbus_interfaces = files(
top_srcdir / 'data' / 'org.freedesktop.ScreenSaver.xml',
top_srcdir / 'data' / 'org.gnome.SessionManager.xml',
top_srcdir / 'data' / 'org.cinnamon.Screenshot.xml',
top_srcdir / 'data' / 'org.gnome.Shell.Screenshot.xml',
top_srcdir / 'data' / 'org.cinnamon.ScreenSaver.xml',
top_srcdir / 'data' / 'org.gnome.ScreenSaver.xml',
top_srcdir / 'data' / 'org.mate.ScreenSaver.xml'
Expand Down
104 changes: 94 additions & 10 deletions src/screenshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "request.h"
#include "utils.h"

static OrgCinnamonScreenshot *cinnamon;
static OrgGnomeShellScreenshot *cinnamon;

typedef struct {
XdpImplScreenshot *impl;
Expand All @@ -28,6 +28,7 @@ typedef struct {

int response;
char *uri;
double red, green, blue;
const char *retval;
char *save_path;
} ScreenshotHandle;
Expand Down Expand Up @@ -62,6 +63,21 @@ send_response (ScreenshotHandle *handle)
handle->response,
g_variant_builder_end (&opt_builder));
}
else
{
GVariantBuilder opt_builder;

g_variant_builder_init (&opt_builder, G_VARIANT_TYPE_VARDICT);
g_variant_builder_add (&opt_builder, "{sv}", "color", g_variant_new ("(ddd)",
handle->red,
handle->green,
handle->blue));

xdp_impl_screenshot_complete_pick_color (handle->impl,
handle->invocation,
handle->response,
g_variant_builder_end (&opt_builder));
}

screenshot_handle_free (handle);
}
Expand Down Expand Up @@ -89,6 +105,42 @@ xfce4_screenshooter_finished (GSubprocess *proc,
send_response (handle);
}

static void
cinnamon_color_pick_done (GObject *source,
GAsyncResult *result,
gpointer data)
{
ScreenshotHandle *handle = data;
GError *error;
GVariant *ret;

error = NULL;

if (!org_gnome_shell_screenshot_call_pick_color_finish (cinnamon,
&ret,
result,
&error))
{
g_print ("Failed to pick color: %s\n", error->message);
g_clear_error (&error);
handle->response = 1;
return;
}
else
if (!g_variant_lookup (ret, "color", "(ddd)",
&handle->red,
&handle->green,
&handle->blue))
{
g_warning ("PickColor didn't return a color");
handle->response = 2;
}

handle->response = 0;

send_response (handle);
}

static void
cinnamon_screenshot_done (GObject *source,
GAsyncResult *result,
Expand All @@ -99,7 +151,7 @@ cinnamon_screenshot_done (GObject *source,
g_autofree char *filename = NULL;
g_autoptr(GError) error = NULL;

if (!org_cinnamon_screenshot_call_screenshot_finish (cinnamon,
if (!org_gnome_shell_screenshot_call_screenshot_finish (cinnamon,
&success,
&filename,
result,
Expand Down Expand Up @@ -156,6 +208,40 @@ construct_filename (void)
return filename;
}


static gboolean
handle_pick_color (XdpImplScreenshot *object,
GDBusMethodInvocation *invocation,
const char *arg_handle,
const char *arg_app_id,
const char *arg_parent_window,
GVariant *arg_options)
{
g_autoptr(Request) request = NULL;
const char *sender;
ScreenshotHandle *handle;

sender = g_dbus_method_invocation_get_sender (invocation);
request = request_new (sender, arg_app_id, arg_handle);

handle = g_new0 (ScreenshotHandle, 1);
handle->impl = object;
handle->invocation = invocation;
handle->request = g_object_ref (request);
handle->retval = "color";
handle->response = 2;

g_signal_connect (request, "handle-close", G_CALLBACK (handle_close), handle);
request_export (request, g_dbus_method_invocation_get_connection (invocation));
org_gnome_shell_screenshot_call_pick_color (cinnamon,
NULL,
cinnamon_color_pick_done,
handle);

return TRUE;
}


static gboolean
handle_screenshot (XdpImplScreenshot *object,
GDBusMethodInvocation *invocation,
Expand Down Expand Up @@ -213,7 +299,7 @@ handle_screenshot (XdpImplScreenshot *object,
else
if (CINNAMON_MODE)
{
org_cinnamon_screenshot_call_screenshot (cinnamon,
org_gnome_shell_screenshot_call_screenshot (cinnamon,
FALSE,
TRUE,
"Screenshot",
Expand All @@ -239,24 +325,22 @@ screenshot_init (GDBusConnection *bus,

helper = G_DBUS_INTERFACE_SKELETON (xdp_impl_screenshot_skeleton_new ());

g_object_set (helper, "version", 1, NULL);
g_object_set (helper, "version", 2, NULL);

// TODO: Need to implement dialog (or maybe interact with screenshot app).
g_signal_connect (helper, "handle-screenshot", G_CALLBACK (handle_screenshot), NULL);

// TODO: Need to implement in Cinnamon
// g_signal_connect (helper, "handle-pick-color", G_CALLBACK (handle_pick_color), NULL);
g_signal_connect (helper, "handle-pick-color", G_CALLBACK (handle_pick_color), NULL);

if (!g_dbus_interface_skeleton_export (helper,
bus,
DESKTOP_PORTAL_OBJECT_PATH,
error))
return FALSE;

cinnamon = org_cinnamon_screenshot_proxy_new_sync (bus,
cinnamon = org_gnome_shell_screenshot_proxy_new_sync (bus,
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
"org.cinnamon.Screenshot",
"/org/cinnamon/Screenshot",
"org.Cinnamon",
"/org/gnome/Shell/Screenshot",
NULL,
error);
if (cinnamon == NULL)
Expand Down