Skip to content

Commit

Permalink
[x11] Fix SystemX11::getColorFromScreen() impl
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Mar 26, 2024
1 parent 7397d46 commit 55fb84c
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions os/x11/system.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// LAF OS Library
// Copyright (C) 2021 Igara Studio S.A.
// Copyright (C) 2021-2024 Igara Studio S.A.
// Copyright (C) 2016 David Capello
//
// This file is released under the terms of the MIT license.
Expand All @@ -14,6 +14,8 @@
#include "os/x11/screen.h"
#include "os/x11/x11.h"

#include <X11/Xutil.h>

namespace os {

class SystemX11 : public CommonSystem {
Expand Down Expand Up @@ -51,28 +53,24 @@ class SystemX11 : public CommonSystem {
}

gfx::Color getColorFromScreen(const gfx::Point& screenPosition) const override {
#if 0
::Display* display = X11::instance()->display();
int screen = XDefaultScreen(display);
::Window root = XDefaultRootWindow(display);
::Window root = XRootWindow(display, screen);

// TODO XGetImage() crashes with a BadMatch error
XImage* image = XGetImage(display, root,
screenPosition.x,
screenPosition.y, 1, 1, AllPlanes, ZPixmap);
if (image) {
XColor color;
color.pixel = XGetPixel(image, screenPosition.x, screenPosition.y);
XFree(image);
color.pixel = XGetPixel(image, 0, 0);
XDestroyImage(image);

XQueryColor(display, XDefaultColormap(display, screen), &color);

// Each red/green/blue channel is 16-bit, so we have to convert to 8-bit.
return gfx::rgba(color.red>>8, color.green>>8, color.blue>>8);
}
else
#endif
return gfx::ColorNone;
return gfx::ColorNone;
}

ScreenRef mainScreen() override {
Expand Down

1 comment on commit 55fb84c

@dacap
Copy link
Member Author

@dacap dacap commented on 55fb84c Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.