2002-12-21 19:54:15 +00:00
|
|
|
// -*- mode: C; indent-tabs-mode: nil; c-basic-offset: 2; -*-
|
2002-12-20 23:19:07 +00:00
|
|
|
|
|
|
|
#include "../config.h"
|
|
|
|
#include "screeninfo.h"
|
|
|
|
#include "display.h"
|
|
|
|
#include "rect.h"
|
|
|
|
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "../src/gettext.h"
|
|
|
|
|
|
|
|
extern PyTypeObject OtkScreenInfo_Type;
|
|
|
|
|
|
|
|
PyObject *OtkScreenInfo_New(int num)
|
|
|
|
{
|
|
|
|
OtkScreenInfo* self;
|
|
|
|
char *dstr, *dstr2;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
self = PyObject_New(OtkScreenInfo, &OtkScreenInfo_Type);
|
|
|
|
|
|
|
|
self->screen = num;
|
|
|
|
self->root_window = RootWindow(OBDisplay->display, self->screen);
|
2002-12-21 12:39:49 +00:00
|
|
|
self->rect = (OtkRect*)
|
|
|
|
OtkRect_New(0, 0, WidthOfScreen(ScreenOfDisplay(OBDisplay->display,
|
|
|
|
self->screen)),
|
|
|
|
HeightOfScreen(ScreenOfDisplay(OBDisplay->display,
|
|
|
|
self->screen)));
|
2002-12-20 23:19:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
If the default depth is at least 8 we will use that,
|
|
|
|
otherwise we try to find the largest TrueColor visual.
|
|
|
|
Preference is given to 24 bit over larger depths if 24 bit is an option.
|
|
|
|
*/
|
|
|
|
|
|
|
|
self->depth = DefaultDepth(OBDisplay->display, self->screen);
|
|
|
|
self->visual = DefaultVisual(OBDisplay->display, self->screen);
|
|
|
|
self->colormap = DefaultColormap(OBDisplay->display, self->screen);
|
|
|
|
|
|
|
|
if (self->depth < 8) {
|
|
|
|
// search for a TrueColor Visual... if we can't find one...
|
|
|
|
// we will use the default visual for the screen
|
|
|
|
XVisualInfo vinfo_template, *vinfo_return;
|
|
|
|
int vinfo_nitems;
|
|
|
|
int best = -1;
|
|
|
|
|
|
|
|
vinfo_template.screen = self->screen;
|
|
|
|
vinfo_template.class = TrueColor;
|
|
|
|
|
|
|
|
vinfo_return = XGetVisualInfo(OBDisplay->display,
|
|
|
|
VisualScreenMask | VisualClassMask,
|
|
|
|
&vinfo_template, &vinfo_nitems);
|
|
|
|
if (vinfo_return) {
|
|
|
|
int max_depth = 1;
|
|
|
|
for (i = 0; i < vinfo_nitems; ++i) {
|
|
|
|
if (vinfo_return[i].depth > max_depth) {
|
|
|
|
if (max_depth == 24 && vinfo_return[i].depth > 24)
|
|
|
|
break; // prefer 24 bit over 32
|
|
|
|
max_depth = vinfo_return[i].depth;
|
|
|
|
best = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (max_depth < self->depth) best = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (best != -1) {
|
|
|
|
self->depth = vinfo_return[best].depth;
|
|
|
|
self->visual = vinfo_return[best].visual;
|
|
|
|
self->colormap = XCreateColormap(OBDisplay->display, self->root_window,
|
|
|
|
self->visual, AllocNone);
|
|
|
|
}
|
|
|
|
|
|
|
|
XFree(vinfo_return);
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the default display string and strip the screen number
|
2002-12-21 12:39:49 +00:00
|
|
|
self->display_string = (PyStringObject*)
|
2002-12-20 23:19:07 +00:00
|
|
|
PyString_FromFormat("DISPLAY=%s",DisplayString(OBDisplay->display));
|
2002-12-21 12:39:49 +00:00
|
|
|
dstr = PyString_AsString((PyObject*)self->display_string);
|
2002-12-20 23:19:07 +00:00
|
|
|
dstr2 = strrchr(dstr, '.');
|
|
|
|
if (dstr2) {
|
|
|
|
PyObject *str;
|
|
|
|
|
2002-12-21 12:39:49 +00:00
|
|
|
_PyString_Resize((PyObject**)&self->display_string, dstr2 - dstr);
|
2002-12-20 23:19:07 +00:00
|
|
|
str = PyString_FromFormat(".%d", self->screen);
|
2002-12-21 12:39:49 +00:00
|
|
|
PyString_Concat((PyObject**)&self->display_string, str);
|
2002-12-20 23:19:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef XINERAMA
|
|
|
|
self->xinerama_active = False;
|
|
|
|
|
|
|
|
if (OtkDisplay->hasXineramaExtensions()) {
|
|
|
|
if (OtkDisplay->getXineramaMajorVersion() == 1) {
|
|
|
|
// we know the version 1(.1?) protocol
|
|
|
|
|
|
|
|
/*
|
|
|
|
in this version of Xinerama, we can't query on a per-screen basis, but
|
|
|
|
in future versions we should be able, so the 'activeness' is checked
|
|
|
|
on a pre-screen basis anyways.
|
|
|
|
*/
|
|
|
|
if (XineramaIsActive(OBDisplay->display)) {
|
|
|
|
/*
|
|
|
|
If Xinerama is being used, there there is only going to be one screen
|
|
|
|
present. We still, of course, want to use the screen class, but that
|
|
|
|
is why no screen number is used in this function call. There should
|
|
|
|
never be more than one screen present with Xinerama active.
|
|
|
|
*/
|
|
|
|
int num;
|
|
|
|
XineramaScreenInfo *info = XineramaQueryScreens(OBDisplay->display,
|
|
|
|
&num);
|
|
|
|
if (num > 0 && info) {
|
|
|
|
self->xinerama_areas = PyList_New(num);
|
|
|
|
for (i = 0; i < num; ++i) {
|
|
|
|
PyList_SetItem(self->xinerama_areas, i,
|
|
|
|
OtkRect_New(info[i].x_org, info[i].y_org,
|
|
|
|
info[i].width, info[i].height));
|
|
|
|
}
|
|
|
|
XFree(info);
|
|
|
|
|
|
|
|
// if we can't find any xinerama regions, then we act as if it is not
|
|
|
|
// active, even though it said it was
|
|
|
|
self->xinerama_active = True;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // XINERAMA
|
|
|
|
|
|
|
|
return (PyObject*)self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static PyObject *otkscreeninfo_getscreen(OtkScreenInfo* self, PyObject* args)
|
|
|
|
{
|
|
|
|
if (!PyArg_ParseTuple(args, ":getScreen"))
|
|
|
|
return NULL;
|
|
|
|
return PyInt_FromLong(self->screen);
|
|
|
|
}
|
|
|
|
|
2002-12-21 12:39:49 +00:00
|
|
|
static OtkRect *otkscreeninfo_getrect(OtkScreenInfo* self, PyObject* args)
|
2002-12-20 23:19:07 +00:00
|
|
|
{
|
|
|
|
if (!PyArg_ParseTuple(args, ":getRect"))
|
|
|
|
return NULL;
|
|
|
|
return self->rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static PyMethodDef get_methods[] = {
|
|
|
|
{"getScreen", (PyCFunction)otkscreeninfo_getscreen, METH_VARARGS,
|
|
|
|
"Get the screen number."},
|
|
|
|
{"getRect", (PyCFunction)otkscreeninfo_getrect, METH_VARARGS,
|
|
|
|
"Get the area taken up by the screen."},
|
|
|
|
{NULL, NULL, 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-12-21 12:41:32 +00:00
|
|
|
static void otkscreeninfo_dealloc(OtkScreenInfo* self)
|
2002-12-20 23:19:07 +00:00
|
|
|
{
|
2002-12-21 12:41:32 +00:00
|
|
|
Py_DECREF(self->display_string);
|
|
|
|
Py_DECREF(self->rect);
|
2002-12-20 23:19:07 +00:00
|
|
|
#ifdef XINERAMA
|
2002-12-21 12:41:32 +00:00
|
|
|
Py_DECREF(self->xinerama_areas);
|
2002-12-20 23:19:07 +00:00
|
|
|
#endif
|
2002-12-21 12:41:32 +00:00
|
|
|
PyObject_Del((PyObject*)self);
|
2002-12-20 23:19:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *otkscreeninfo_getattr(PyObject *obj, char *name)
|
|
|
|
{
|
|
|
|
return Py_FindMethod(get_methods, obj, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PyTypeObject OtkScreenInfo_Type = {
|
|
|
|
PyObject_HEAD_INIT(NULL)
|
|
|
|
0,
|
|
|
|
"OtkScreenInfo",
|
|
|
|
sizeof(OtkScreenInfo),
|
|
|
|
0,
|
2002-12-21 12:41:32 +00:00
|
|
|
(destructor)otkscreeninfo_dealloc, /*tp_dealloc*/
|
2002-12-20 23:19:07 +00:00
|
|
|
0, /*tp_print*/
|
|
|
|
otkscreeninfo_getattr, /*tp_getattr*/
|
|
|
|
0, /*tp_setattr*/
|
|
|
|
0, /*tp_compare*/
|
|
|
|
0, /*tp_repr*/
|
|
|
|
0, /*tp_as_number*/
|
|
|
|
0, /*tp_as_sequence*/
|
|
|
|
0, /*tp_as_mapping*/
|
|
|
|
0, /*tp_hash */
|
|
|
|
};
|