-
Notifications
You must be signed in to change notification settings - Fork 8
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
Conversation
Looks like this is as far as I can get on my own. Here is a generic color picker for use with this patch: #include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/cursorfont.h>
#include <stdio.h>
int main()
{
Display* display = XOpenDisplay(NULL);
Window window = DefaultRootWindow(display);
Cursor cursor = XCreateFontCursor(display, XC_crosshair);
XGrabPointer(display,
window,
False,
ButtonPressMask,
GrabModeAsync,
GrabModeAsync,
None,
cursor,
CurrentTime);
// Wait for click event to take screenshot
XEvent event;
XImage* image = NULL;
while (1) {
XNextEvent(display, &event);
if (event.type == ButtonPress) {
image = XGetImage(display,
window,
event.xbutton.x,
event.xbutton.y,
1,
1,
AllPlanes,
ZPixmap);
break;
}
}
// Get and print pixel color from screenshot
XColor color;
color.pixel = XGetPixel(image, 0, 0);
unsigned char r = (color.pixel & image->red_mask) >> 16;
unsigned char g = (color.pixel & image->green_mask) >> 8;
unsigned char b = color.pixel & image->blue_mask;
printf("[%u,%u,%u]", r, g, b);
// Clean up
XDestroyImage(image);
XUngrabPointer(display, CurrentTime);
XFreeCursor(display, cursor);
XCloseDisplay(display);
return 0;
} If you install it as @mtwebster @clefebvre Any assistance would be appreciated :) |
Wow, it actually works now. Screencast.from.2023-11-25.16-30-35.webmAnyway: this expects a color picker binary called "mint-color-picker" that outputs colors in an |
I appreciate the effort in this (and the actual portal stuff looks fine), but there's no reason to have a separate tool to actually pick the color - we can do this in Cinnamon (using the same mechanism as we use for area screenshots), and avoid relying directly upon xlib. Have a look at gnome's implementation, ours would be similar in cinnamon: Like I said, much of it is already there, as part of the area-screenshot code. |
Hi, I just opened a pull request to this pull request: Once you merge that I can merge this PR |
Thanks! Once we figure out whether or not we want to provide xfce/mate support for this or not, we may incorporate your standalone picker as well. |
This would fix all the Flatpak color pickers (such as Eyedropper) as well as any Flatpak app that uses a color picker widget for any purpose (such as Gradience). Having these not work for no apparent reason is not great considering that Mint allows the user to install Flatpaks out of the box.
I noticed the lack of progress here, so I thought I'd try to implement this myself.
Fixes #4.