add support for linux, but with limitation

master
chaosddp 2018-05-07 17:45:56 +08:00
parent 612ecdab54
commit a7974ba8a5
5 changed files with 915 additions and 79 deletions

590
defos/include/Xrandr.h Normal file
View File

@ -0,0 +1,590 @@
/*
* Copyright © 2000 Compaq Computer Corporation, Inc.
* Copyright © 2002 Hewlett-Packard Company, Inc.
* Copyright © 2006 Intel Corporation
* Copyright © 2008 Red Hat, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting documentation, and
* that the name of the copyright holders not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. The copyright holders make no representations
* about the suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*
* Author: Jim Gettys, HP Labs, Hewlett-Packard, Inc.
* Keith Packard, Intel Corporation
*/
#if defined(DM_PLATFORM_LINUX)
#ifndef _XRANDR_H_
#define _XRANDR_H_
#include <randr.h>
#include <X11/extensions/Xrender.h>
#include <X11/Xfuncproto.h>
_XFUNCPROTOBEGIN
typedef XID RROutput;
typedef XID RRCrtc;
typedef XID RRMode;
typedef XID RRProvider;
typedef struct {
int width, height;
int mwidth, mheight;
} XRRScreenSize;
/*
* Events.
*/
typedef struct {
int type; /* event base */
unsigned long serial; /* # of last request processed by server */
Bool send_event; /* true if this came from a SendEvent request */
Display *display; /* Display the event was read from */
Window window; /* window which selected for this event */
Window root; /* Root window for changed screen */
Time timestamp; /* when the screen change occurred */
Time config_timestamp; /* when the last configuration change */
SizeID size_index;
SubpixelOrder subpixel_order;
Rotation rotation;
int width;
int height;
int mwidth;
int mheight;
} XRRScreenChangeNotifyEvent;
typedef struct {
int type; /* event base */
unsigned long serial; /* # of last request processed by server */
Bool send_event; /* true if this came from a SendEvent request */
Display *display; /* Display the event was read from */
Window window; /* window which selected for this event */
int subtype; /* RRNotify_ subtype */
} XRRNotifyEvent;
typedef struct {
int type; /* event base */
unsigned long serial; /* # of last request processed by server */
Bool send_event; /* true if this came from a SendEvent request */
Display *display; /* Display the event was read from */
Window window; /* window which selected for this event */
int subtype; /* RRNotify_OutputChange */
RROutput output; /* affected output */
RRCrtc crtc; /* current crtc (or None) */
RRMode mode; /* current mode (or None) */
Rotation rotation; /* current rotation of associated crtc */
Connection connection; /* current connection status */
SubpixelOrder subpixel_order;
} XRROutputChangeNotifyEvent;
typedef struct {
int type; /* event base */
unsigned long serial; /* # of last request processed by server */
Bool send_event; /* true if this came from a SendEvent request */
Display *display; /* Display the event was read from */
Window window; /* window which selected for this event */
int subtype; /* RRNotify_CrtcChange */
RRCrtc crtc; /* current crtc (or None) */
RRMode mode; /* current mode (or None) */
Rotation rotation; /* current rotation of associated crtc */
int x, y; /* position */
unsigned int width, height; /* size */
} XRRCrtcChangeNotifyEvent;
typedef struct {
int type; /* event base */
unsigned long serial; /* # of last request processed by server */
Bool send_event; /* true if this came from a SendEvent request */
Display *display; /* Display the event was read from */
Window window; /* window which selected for this event */
int subtype; /* RRNotify_OutputProperty */
RROutput output; /* related output */
Atom property; /* changed property */
Time timestamp; /* time of change */
int state; /* NewValue, Deleted */
} XRROutputPropertyNotifyEvent;
typedef struct {
int type; /* event base */
unsigned long serial; /* # of last request processed by server */
Bool send_event; /* true if this came from a SendEvent request */
Display *display; /* Display the event was read from */
Window window; /* window which selected for this event */
int subtype; /* RRNotify_ProviderChange */
RRProvider provider; /* current provider (or None) */
Time timestamp; /* time of change */
unsigned int current_role;
} XRRProviderChangeNotifyEvent;
typedef struct {
int type; /* event base */
unsigned long serial; /* # of last request processed by server */
Bool send_event; /* true if this came from a SendEvent request */
Display *display; /* Display the event was read from */
Window window; /* window which selected for this event */
int subtype; /* RRNotify_ProviderProperty */
RRProvider provider; /* related provider */
Atom property; /* changed property */
Time timestamp; /* time of change */
int state; /* NewValue, Deleted */
} XRRProviderPropertyNotifyEvent;
typedef struct {
int type; /* event base */
unsigned long serial; /* # of last request processed by server */
Bool send_event; /* true if this came from a SendEvent request */
Display *display; /* Display the event was read from */
Window window; /* window which selected for this event */
int subtype; /* RRNotify_ResourceChange */
Time timestamp; /* time of change */
} XRRResourceChangeNotifyEvent;
/* internal representation is private to the library */
typedef struct _XRRScreenConfiguration XRRScreenConfiguration;
Bool XRRQueryExtension (Display *dpy,
int *event_base_return,
int *error_base_return);
Status XRRQueryVersion (Display *dpy,
int *major_version_return,
int *minor_version_return);
XRRScreenConfiguration *XRRGetScreenInfo (Display *dpy,
Window window);
void XRRFreeScreenConfigInfo (XRRScreenConfiguration *config);
/*
* Note that screen configuration changes are only permitted if the client can
* prove it has up to date configuration information. We are trying to
* insist that it become possible for screens to change dynamically, so
* we want to ensure the client knows what it is talking about when requesting
* changes.
*/
Status XRRSetScreenConfig (Display *dpy,
XRRScreenConfiguration *config,
Drawable draw,
int size_index,
Rotation rotation,
Time timestamp);
/* added in v1.1, sorry for the lame name */
Status XRRSetScreenConfigAndRate (Display *dpy,
XRRScreenConfiguration *config,
Drawable draw,
int size_index,
Rotation rotation,
short rate,
Time timestamp);
Rotation XRRConfigRotations(XRRScreenConfiguration *config, Rotation *current_rotation);
Time XRRConfigTimes (XRRScreenConfiguration *config, Time *config_timestamp);
XRRScreenSize *XRRConfigSizes(XRRScreenConfiguration *config, int *nsizes);
short *XRRConfigRates (XRRScreenConfiguration *config, int sizeID, int *nrates);
SizeID XRRConfigCurrentConfiguration (XRRScreenConfiguration *config,
Rotation *rotation);
short XRRConfigCurrentRate (XRRScreenConfiguration *config);
int XRRRootToScreen(Display *dpy, Window root);
/*
* returns the screen configuration for the specified screen; does a lazy
* evalution to delay getting the information, and caches the result.
* These routines should be used in preference to XRRGetScreenInfo
* to avoid unneeded round trips to the X server. These are new
* in protocol version 0.1.
*/
void XRRSelectInput(Display *dpy, Window window, int mask);
/*
* the following are always safe to call, even if RandR is not implemented
* on a screen
*/
Rotation XRRRotations(Display *dpy, int screen, Rotation *current_rotation);
XRRScreenSize *XRRSizes(Display *dpy, int screen, int *nsizes);
short *XRRRates (Display *dpy, int screen, int sizeID, int *nrates);
Time XRRTimes (Display *dpy, int screen, Time *config_timestamp);
/* Version 1.2 additions */
/* despite returning a Status, this returns 1 for success */
Status
XRRGetScreenSizeRange (Display *dpy, Window window,
int *minWidth, int *minHeight,
int *maxWidth, int *maxHeight);
void
XRRSetScreenSize (Display *dpy, Window window,
int width, int height,
int mmWidth, int mmHeight);
typedef unsigned long XRRModeFlags;
typedef struct _XRRModeInfo {
RRMode id;
unsigned int width;
unsigned int height;
unsigned long dotClock;
unsigned int hSyncStart;
unsigned int hSyncEnd;
unsigned int hTotal;
unsigned int hSkew;
unsigned int vSyncStart;
unsigned int vSyncEnd;
unsigned int vTotal;
char *name;
unsigned int nameLength;
XRRModeFlags modeFlags;
} XRRModeInfo;
typedef struct _XRRScreenResources {
Time timestamp;
Time configTimestamp;
int ncrtc;
RRCrtc *crtcs;
int noutput;
RROutput *outputs;
int nmode;
XRRModeInfo *modes;
} XRRScreenResources;
XRRScreenResources *
XRRGetScreenResources (Display *dpy, Window window);
void
XRRFreeScreenResources (XRRScreenResources *resources);
typedef struct _XRROutputInfo {
Time timestamp;
RRCrtc crtc;
char *name;
int nameLen;
unsigned long mm_width;
unsigned long mm_height;
Connection connection;
SubpixelOrder subpixel_order;
int ncrtc;
RRCrtc *crtcs;
int nclone;
RROutput *clones;
int nmode;
int npreferred;
RRMode *modes;
} XRROutputInfo;
XRROutputInfo *
XRRGetOutputInfo (Display *dpy, XRRScreenResources *resources, RROutput output);
void
XRRFreeOutputInfo (XRROutputInfo *outputInfo);
Atom *
XRRListOutputProperties (Display *dpy, RROutput output, int *nprop);
typedef struct {
Bool pending;
Bool range;
Bool immutable;
int num_values;
long *values;
} XRRPropertyInfo;
XRRPropertyInfo *
XRRQueryOutputProperty (Display *dpy, RROutput output, Atom property);
void
XRRConfigureOutputProperty (Display *dpy, RROutput output, Atom property,
Bool pending, Bool range, int num_values,
long *values);
void
XRRChangeOutputProperty (Display *dpy, RROutput output,
Atom property, Atom type,
int format, int mode,
_Xconst unsigned char *data, int nelements);
void
XRRDeleteOutputProperty (Display *dpy, RROutput output, Atom property);
int
XRRGetOutputProperty (Display *dpy, RROutput output,
Atom property, long offset, long length,
Bool _delete, Bool pending, Atom req_type,
Atom *actual_type, int *actual_format,
unsigned long *nitems, unsigned long *bytes_after,
unsigned char **prop);
XRRModeInfo *
XRRAllocModeInfo (_Xconst char *name, int nameLength);
RRMode
XRRCreateMode (Display *dpy, Window window, XRRModeInfo *modeInfo);
void
XRRDestroyMode (Display *dpy, RRMode mode);
void
XRRAddOutputMode (Display *dpy, RROutput output, RRMode mode);
void
XRRDeleteOutputMode (Display *dpy, RROutput output, RRMode mode);
void
XRRFreeModeInfo (XRRModeInfo *modeInfo);
typedef struct _XRRCrtcInfo {
Time timestamp;
int x, y;
unsigned int width, height;
RRMode mode;
Rotation rotation;
int noutput;
RROutput *outputs;
Rotation rotations;
int npossible;
RROutput *possible;
} XRRCrtcInfo;
XRRCrtcInfo *
XRRGetCrtcInfo (Display *dpy, XRRScreenResources *resources, RRCrtc crtc);
void
XRRFreeCrtcInfo (XRRCrtcInfo *crtcInfo);
Status
XRRSetCrtcConfig (Display *dpy,
XRRScreenResources *resources,
RRCrtc crtc,
Time timestamp,
int x, int y,
RRMode mode,
Rotation rotation,
RROutput *outputs,
int noutputs);
int
XRRGetCrtcGammaSize (Display *dpy, RRCrtc crtc);
typedef struct _XRRCrtcGamma {
int size;
unsigned short *red;
unsigned short *green;
unsigned short *blue;
} XRRCrtcGamma;
XRRCrtcGamma *
XRRGetCrtcGamma (Display *dpy, RRCrtc crtc);
XRRCrtcGamma *
XRRAllocGamma (int size);
void
XRRSetCrtcGamma (Display *dpy, RRCrtc crtc, XRRCrtcGamma *gamma);
void
XRRFreeGamma (XRRCrtcGamma *gamma);
/* Version 1.3 additions */
XRRScreenResources *
XRRGetScreenResourcesCurrent (Display *dpy, Window window);
void
XRRSetCrtcTransform (Display *dpy,
RRCrtc crtc,
XTransform *transform,
_Xconst char *filter,
XFixed *params,
int nparams);
typedef struct _XRRCrtcTransformAttributes {
XTransform pendingTransform;
char *pendingFilter;
int pendingNparams;
XFixed *pendingParams;
XTransform currentTransform;
char *currentFilter;
int currentNparams;
XFixed *currentParams;
} XRRCrtcTransformAttributes;
/*
* Get current crtc transforms and filters.
* Pass *attributes to XFree to free
*/
Status
XRRGetCrtcTransform (Display *dpy,
RRCrtc crtc,
XRRCrtcTransformAttributes **attributes);
/*
* intended to take RRScreenChangeNotify, or
* ConfigureNotify (on the root window)
* returns 1 if it is an event type it understands, 0 if not
*/
int XRRUpdateConfiguration(XEvent *event);
typedef struct _XRRPanning {
Time timestamp;
unsigned int left;
unsigned int top;
unsigned int width;
unsigned int height;
unsigned int track_left;
unsigned int track_top;
unsigned int track_width;
unsigned int track_height;
int border_left;
int border_top;
int border_right;
int border_bottom;
} XRRPanning;
XRRPanning *
XRRGetPanning (Display *dpy, XRRScreenResources *resources, RRCrtc crtc);
void
XRRFreePanning (XRRPanning *panning);
Status
XRRSetPanning (Display *dpy,
XRRScreenResources *resources,
RRCrtc crtc,
XRRPanning *panning);
void
XRRSetOutputPrimary(Display *dpy,
Window window,
RROutput output);
RROutput
XRRGetOutputPrimary(Display *dpy,
Window window);
typedef struct _XRRProviderResources {
Time timestamp;
int nproviders;
RRProvider *providers;
} XRRProviderResources;
XRRProviderResources *
XRRGetProviderResources(Display *dpy, Window window);
void
XRRFreeProviderResources(XRRProviderResources *resources);
typedef struct _XRRProviderInfo {
unsigned int capabilities;
int ncrtcs;
RRCrtc *crtcs;
int noutputs;
RROutput *outputs;
char *name;
int nassociatedproviders;
RRProvider *associated_providers;
unsigned int *associated_capability;
int nameLen;
} XRRProviderInfo;
XRRProviderInfo *
XRRGetProviderInfo(Display *dpy, XRRScreenResources *resources, RRProvider provider);
void
XRRFreeProviderInfo(XRRProviderInfo *provider);
int
XRRSetProviderOutputSource(Display *dpy, XID provider, XID source_provider);
int
XRRSetProviderOffloadSink(Display *dpy, XID provider, XID sink_provider);
Atom *
XRRListProviderProperties (Display *dpy, RRProvider provider, int *nprop);
XRRPropertyInfo *
XRRQueryProviderProperty (Display *dpy, RRProvider provider, Atom property);
void
XRRConfigureProviderProperty (Display *dpy, RRProvider provider, Atom property,
Bool pending, Bool range, int num_values,
long *values);
void
XRRChangeProviderProperty (Display *dpy, RRProvider provider,
Atom property, Atom type,
int format, int mode,
_Xconst unsigned char *data, int nelements);
void
XRRDeleteProviderProperty (Display *dpy, RRProvider provider, Atom property);
int
XRRGetProviderProperty (Display *dpy, RRProvider provider,
Atom property, long offset, long length,
Bool _delete, Bool pending, Atom req_type,
Atom *actual_type, int *actual_format,
unsigned long *nitems, unsigned long *bytes_after,
unsigned char **prop);
typedef struct _XRRMonitorInfo {
Atom name;
Bool primary;
Bool automatic;
int noutput;
int x;
int y;
int width;
int height;
int mwidth;
int mheight;
RROutput *outputs;
} XRRMonitorInfo;
XRRMonitorInfo *
XRRAllocateMonitor(Display *dpy, int noutput);
XRRMonitorInfo *
XRRGetMonitors(Display *dpy, Window window, Bool get_active, int *nmonitors);
void
XRRSetMonitor(Display *dpy, Window window, XRRMonitorInfo *monitor);
void
XRRDeleteMonitor(Display *dpy, Window window, Atom name);
void
XRRFreeMonitors(XRRMonitorInfo *monitors);
_XFUNCPROTOEND
#endif /* _XRANDR_H_ */
#endif

200
defos/include/randr.h Normal file
View File

@ -0,0 +1,200 @@
/*
* Copyright © 2000 Compaq Computer Corporation
* Copyright © 2002 Hewlett Packard Company
* Copyright © 2006 Intel Corporation
* Copyright © 2008 Red Hat, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting documentation, and
* that the name of the copyright holders not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. The copyright holders make no representations
* about the suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*
* Author: Jim Gettys, HP Labs, Hewlett-Packard, Inc.
* Keith Packard, Intel Corporation
*/
#if defined(DM_PLATFORM_LINUX)
#ifndef _RANDR_H_
#define _RANDR_H_
typedef unsigned short Rotation;
typedef unsigned short SizeID;
typedef unsigned short SubpixelOrder;
typedef unsigned short Connection;
typedef unsigned short XRandrRotation;
typedef unsigned short XRandrSizeID;
typedef unsigned short XRandrSubpixelOrder;
typedef unsigned long XRandrModeFlags;
#define RANDR_NAME "RANDR"
#define RANDR_MAJOR 1
#define RANDR_MINOR 5
#define RRNumberErrors 4
#define RRNumberEvents 2
#define RRNumberRequests 45
#define X_RRQueryVersion 0
/* we skip 1 to make old clients fail pretty immediately */
#define X_RROldGetScreenInfo 1
#define X_RR1_0SetScreenConfig 2
/* V1.0 apps share the same set screen config request id */
#define X_RRSetScreenConfig 2
#define X_RROldScreenChangeSelectInput 3
/* 3 used to be ScreenChangeSelectInput; deprecated */
#define X_RRSelectInput 4
#define X_RRGetScreenInfo 5
/* V1.2 additions */
#define X_RRGetScreenSizeRange 6
#define X_RRSetScreenSize 7
#define X_RRGetScreenResources 8
#define X_RRGetOutputInfo 9
#define X_RRListOutputProperties 10
#define X_RRQueryOutputProperty 11
#define X_RRConfigureOutputProperty 12
#define X_RRChangeOutputProperty 13
#define X_RRDeleteOutputProperty 14
#define X_RRGetOutputProperty 15
#define X_RRCreateMode 16
#define X_RRDestroyMode 17
#define X_RRAddOutputMode 18
#define X_RRDeleteOutputMode 19
#define X_RRGetCrtcInfo 20
#define X_RRSetCrtcConfig 21
#define X_RRGetCrtcGammaSize 22
#define X_RRGetCrtcGamma 23
#define X_RRSetCrtcGamma 24
/* V1.3 additions */
#define X_RRGetScreenResourcesCurrent 25
#define X_RRSetCrtcTransform 26
#define X_RRGetCrtcTransform 27
#define X_RRGetPanning 28
#define X_RRSetPanning 29
#define X_RRSetOutputPrimary 30
#define X_RRGetOutputPrimary 31
#define RRTransformUnit (1L << 0)
#define RRTransformScaleUp (1L << 1)
#define RRTransformScaleDown (1L << 2)
#define RRTransformProjective (1L << 3)
/* v1.4 */
#define X_RRGetProviders 32
#define X_RRGetProviderInfo 33
#define X_RRSetProviderOffloadSink 34
#define X_RRSetProviderOutputSource 35
#define X_RRListProviderProperties 36
#define X_RRQueryProviderProperty 37
#define X_RRConfigureProviderProperty 38
#define X_RRChangeProviderProperty 39
#define X_RRDeleteProviderProperty 40
#define X_RRGetProviderProperty 41
/* v1.5 */
#define X_RRGetMonitors 42
#define X_RRSetMonitor 43
#define X_RRDeleteMonitor 44
/* Event selection bits */
#define RRScreenChangeNotifyMask (1L << 0)
/* V1.2 additions */
#define RRCrtcChangeNotifyMask (1L << 1)
#define RROutputChangeNotifyMask (1L << 2)
#define RROutputPropertyNotifyMask (1L << 3)
/* V1.4 additions */
#define RRProviderChangeNotifyMask (1L << 4)
#define RRProviderPropertyNotifyMask (1L << 5)
#define RRResourceChangeNotifyMask (1L << 6)
/* Event codes */
#define RRScreenChangeNotify 0
/* V1.2 additions */
#define RRNotify 1
/* RRNotify Subcodes */
#define RRNotify_CrtcChange 0
#define RRNotify_OutputChange 1
#define RRNotify_OutputProperty 2
#define RRNotify_ProviderChange 3
#define RRNotify_ProviderProperty 4
#define RRNotify_ResourceChange 5
/* used in the rotation field; rotation and reflection in 0.1 proto. */
#define RR_Rotate_0 1
#define RR_Rotate_90 2
#define RR_Rotate_180 4
#define RR_Rotate_270 8
/* new in 1.0 protocol, to allow reflection of screen */
#define RR_Reflect_X 16
#define RR_Reflect_Y 32
#define RRSetConfigSuccess 0
#define RRSetConfigInvalidConfigTime 1
#define RRSetConfigInvalidTime 2
#define RRSetConfigFailed 3
/* new in 1.2 protocol */
#define RR_HSyncPositive 0x00000001
#define RR_HSyncNegative 0x00000002
#define RR_VSyncPositive 0x00000004
#define RR_VSyncNegative 0x00000008
#define RR_Interlace 0x00000010
#define RR_DoubleScan 0x00000020
#define RR_CSync 0x00000040
#define RR_CSyncPositive 0x00000080
#define RR_CSyncNegative 0x00000100
#define RR_HSkewPresent 0x00000200
#define RR_BCast 0x00000400
#define RR_PixelMultiplex 0x00000800
#define RR_DoubleClock 0x00001000
#define RR_ClockDivideBy2 0x00002000
#define RR_Connected 0
#define RR_Disconnected 1
#define RR_UnknownConnection 2
#define BadRROutput 0
#define BadRRCrtc 1
#define BadRRMode 2
#define BadRRProvider 3
/* Conventional RandR output properties */
#define RR_PROPERTY_BACKLIGHT "Backlight"
#define RR_PROPERTY_RANDR_EDID "EDID"
#define RR_PROPERTY_SIGNAL_FORMAT "SignalFormat"
#define RR_PROPERTY_SIGNAL_PROPERTIES "SignalProperties"
#define RR_PROPERTY_CONNECTOR_TYPE "ConnectorType"
#define RR_PROPERTY_CONNECTOR_NUMBER "ConnectorNumber"
#define RR_PROPERTY_COMPATIBILITY_LIST "CompatibilityList"
#define RR_PROPERTY_CLONE_LIST "CloneList"
#define RR_PROPERTY_BORDER "Border"
#define RR_PROPERTY_BORDER_DIMENSIONS "BorderDimensions"
#define RR_PROPERTY_GUID "GUID"
#define RR_PROPERTY_RANDR_TILE "TILE"
/* roles this device can carry out */
#define RR_Capability_None 0
#define RR_Capability_SourceOutput 1
#define RR_Capability_SinkOutput 2
#define RR_Capability_SourceOffload 4
#define RR_Capability_SinkOffload 8
#endif /* _RANDR_H_ */
#endif

Binary file not shown.

View File

@ -291,7 +291,7 @@ static int get_display_list(lua_State *L)
// final result
lua_newtable(L);
#if defined(DM_PLATFORM_WINDOWS) || defined(DM_PLATFORM_OSX)
#if defined(DM_PLATFORM_WINDOWS) || defined(DM_PLATFORM_OSX) || defined(DM_PLATFORM_LINUX)
dmArray<DisplayInfo>* displaylist = new dmArray<DisplayInfo>();
defos_get_display_info(displaylist);

View File

@ -17,10 +17,11 @@
#include <X11/Xos.h>
#include <X11/cursorfont.h>
#include <Xcursor.h>
#include <Xrandr.h>
//static GC gc;
#define _NET_WM_STATE_REMOVE 0
#define _NET_WM_STATE_ADD 1
#define _NET_WM_STATE_REMOVE 0
#define _NET_WM_STATE_ADD 1
#define _NET_WM_STATE_TOGGLE 2
#define XATOM(name) XInternAtom(disp, name, False)
@ -42,12 +43,10 @@ static Atom NET_WM_ACTION_MINIMIZE;
static bool is_maximized = false;
static bool is_fullscreen = false;
static Cursor custom_cursor;// image cursor
static Cursor custom_cursor; // image cursor
static bool is_window_visible(Window window);
static void send_message(Window& window, Atom type, long a, long b, long c, long d,long e);
static void send_message(Window &window, Atom type, long a, long b, long c, long d, long e);
void defos_init()
{
@ -67,16 +66,14 @@ void defos_init()
void defos_final()
{
if(custom_cursor==NULL)
if (custom_cursor == NULL)
{
XFreeCursor(disp, custom_cursor);
}
}
void defos_event_handler_was_set(DefosEvent event)
{
}
bool defos_is_fullscreen()
@ -121,26 +118,26 @@ bool defos_is_cursor_visible()
void defos_toggle_fullscreen()
{
if(!is_fullscreen)
if (!is_fullscreen)
{
send_message(win,
NET_WM_STATE,
_NET_WM_STATE_ADD,
NET_WM_STATE_FULLSCREEN,
0,
1,
0);
;
NET_WM_STATE,
_NET_WM_STATE_ADD,
NET_WM_STATE_FULLSCREEN,
0,
1,
0);
;
}
else
{
send_message(win,
NET_WM_STATE,
_NET_WM_STATE_REMOVE,
NET_WM_STATE_FULLSCREEN,
0,
1,
0);
NET_WM_STATE,
_NET_WM_STATE_REMOVE,
NET_WM_STATE_FULLSCREEN,
0,
1,
0);
}
is_fullscreen = !is_fullscreen;
@ -149,25 +146,25 @@ void defos_toggle_fullscreen()
void defos_toggle_maximized()
{
if(!is_maximized)
if (!is_maximized)
{
send_message(win,
NET_WM_STATE,
_NET_WM_STATE_ADD,
NET_WM_STATE_MAXIMIZED_VERT,
NET_WM_STATE_MAXIMIZED_HORZ,
1,
0);
send_message(win,
NET_WM_STATE,
_NET_WM_STATE_ADD,
NET_WM_STATE_MAXIMIZED_VERT,
NET_WM_STATE_MAXIMIZED_HORZ,
1,
0);
}
else
{
send_message(win,
NET_WM_STATE,
_NET_WM_STATE_REMOVE,
NET_WM_STATE_MAXIMIZED_VERT,
NET_WM_STATE_MAXIMIZED_HORZ,
1,
0);
NET_WM_STATE,
_NET_WM_STATE_REMOVE,
NET_WM_STATE_MAXIMIZED_VERT,
NET_WM_STATE_MAXIMIZED_HORZ,
1,
0);
}
is_maximized = !is_maximized;
@ -187,16 +184,17 @@ bool defos_is_console_visible()
void defos_set_window_size(float x, float y, float w, float h)
{
// change size only if it is visible
if(is_window_visible(win))
if (is_window_visible(win))
{
if(isnan(x) || isnan(y)){
if (isnan(x) || isnan(y))
{
XWindowAttributes attributes;
XGetWindowAttributes(disp, root, &attributes);
x = ((float)attributes.width - w)/2;
y = ((float)attributes.height - h)/2;
x = ((float)attributes.width - w) / 2;
y = ((float)attributes.height - h) / 2;
}
XMoveResizeWindow(disp, win, (int)x, (int)y, (unsigned int)w, (unsigned int)h);
XFlush(disp);
}
@ -209,14 +207,14 @@ void defos_set_view_size(float x, float y, float w, float h)
changes.y = (int)y;
changes.width = (int)w;
changes.height = (int)h;
XConfigureWindow(disp, win, CWX | CWY | CWWidth | CWHeight, &changes);
XFlush(disp);
}
void defos_set_window_title(const char *title_lua)
{
XChangeProperty(disp, win, NET_WM_NAME, UTF8_STRING, 8, PropModeReplace, (unsigned char*)title_lua, strlen(title_lua));
XChangeProperty(disp, win, NET_WM_NAME, UTF8_STRING, 8, PropModeReplace, (unsigned char *)title_lua, strlen(title_lua));
XFlush(disp); // IMPORTANT: we have to flush, or nothing will be changed
}
@ -228,7 +226,7 @@ WinRect defos_get_window_size()
WinRect defos_get_view_size()
{
int x,y;
int x, y;
unsigned int w, h, bw, depth;
Window dummy;
@ -247,20 +245,23 @@ void defos_set_cursor_pos(float x, float y)
void defos_move_cursor_to(float x, float y)
{
WinRect rect = defos_get_window_size();
WinRect rect = defos_get_window_size();
int ix = (int)x;
int iy = (int)y;
int ix = (int)x;
int iy = (int)y;
// TODO: need this?
if(ix > rect.w) ix = rect.w;
if(ix < 0) ix = 0;
if(iy > rect.h) iy=rect.h;
if(iy < 0) iy = 0;
// TODO: need this?
if (ix > rect.w)
ix = rect.w;
if (ix < 0)
ix = 0;
if (iy > rect.h)
iy = rect.h;
if (iy < 0)
iy = 0;
XWarpPointer(disp, None, win, 0, 0, 0, 0, ix, iy);
XFlush(disp);
XWarpPointer(disp, None, win, 0, 0, 0, 0, ix, iy);
XFlush(disp);
}
void defos_set_cursor_clipped(bool clipped)
@ -283,8 +284,8 @@ bool defos_is_cursor_locked()
return false;
}
void defos_update() {
void defos_update()
{
}
void defos_set_custom_cursor_linux(const char *filename)
@ -307,27 +308,72 @@ void defos_reset_cursor()
{
XUndefineCursor(disp, win);
if(custom_cursor!=NULL)
if (custom_cursor != NULL)
{
XFreeCursor(disp, custom_cursor);
custom_cursor = NULL;
}
}
static const XRRModeInfo* getModeInfo(const XRRScreenResources* sr, RRMode id){
for(int i=0;i<sr->nmode;i++){
if(sr->modes[i].id == id){
return sr->modes+i;
}
}
return NULL;
}
static long calculateRefreshRate(const XRRModeInfo* mi)
{
if (!mi->hTotal || !mi->vTotal)
return 0;
return (long) ((double) mi->dotClock / ((double) mi->hTotal * (double) mi->vTotal));
}
// NOTE: seems like this function only can query those that with 60 fraquency
void defos_get_display_info(dmArray<DisplayInfo> *displist)
{
RROutput output = XRRGetOutputPrimary(disp, win);
XRRScreenResources *res = XRRGetScreenResourcesCurrent(disp, win);
XRROutputInfo *oi= XRRGetOutputInfo(disp, res, output);
long bpp = (long)DefaultDepth(disp, screen);
for(int i=0;i<oi->nmode;i++){
const XRRModeInfo *mi = getModeInfo(res, oi->modes[i]);
DisplayInfo info;
// TODO: add rotation detect
info.w = (long)mi->width;
info.h= (long)mi->height;
info.frequency = calculateRefreshRate(mi);
info.bitsPerPixel = bpp;
displist->OffsetCapacity(1);
displist->Push(info);
}
XRRFreeOutputInfo(oi);
XRRFreeScreenResources(res);
}
static unsigned int get_cursor(DefosCursor cursor)
{
switch(cursor)
switch (cursor)
{
case DEFOS_CURSOR_ARROW:
return XC_left_ptr;
case DEFOS_CURSOR_CROSSHAIR:
return XC_tcross;
case DEFOS_CURSOR_HAND:
return XC_hand2;
case DEFOS_CURSOR_IBEAM:
return XC_xterm;
default:
return XC_left_ptr;
case DEFOS_CURSOR_ARROW:
return XC_left_ptr;
case DEFOS_CURSOR_CROSSHAIR:
return XC_tcross;
case DEFOS_CURSOR_HAND:
return XC_hand2;
case DEFOS_CURSOR_IBEAM:
return XC_xterm;
default:
return XC_left_ptr;
}
}
@ -339,7 +385,7 @@ static bool is_window_visible(Window window)
}
//from glfw/x11_window.c
static void send_message(Window& window, Atom type, long a, long b, long c, long d,long e)
static void send_message(Window &window, Atom type, long a, long b, long c, long d, long e)
{
XEvent event;
memset(&event, 0, sizeof(event));
@ -348,13 +394,13 @@ static void send_message(Window& window, Atom type, long a, long b, long c, long
event.xclient.window = window;
event.xclient.format = 32;
event.xclient.message_type = type;
event.xclient.data.l[0]=a;
event.xclient.data.l[1]=b;
event.xclient.data.l[2]=c;
event.xclient.data.l[3]=d;
event.xclient.data.l[4]=e;
XSendEvent(disp, root, False, SubstructureNotifyMask|SubstructureRedirectMask, &event);
event.xclient.data.l[0] = a;
event.xclient.data.l[1] = b;
event.xclient.data.l[2] = c;
event.xclient.data.l[3] = d;
event.xclient.data.l[4] = e;
XSendEvent(disp, root, False, SubstructureNotifyMask | SubstructureRedirectMask, &event);
}
#endif