1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
/*
* Copyright © 2012 Gerd Kohlberger <lowfi@chello.at>
* Copyright © 2012-2013 marmuta <marmvta@gmail.com>
*
* This file is part of Onboard.
*
* Onboard is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Onboard is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "osk_module.h"
#include <gdk/gdkx.h>
#include <X11/Xatom.h>
typedef struct {
PyObject_HEAD
} OskStruts;
OSK_REGISTER_TYPE (OskStruts, osk_struts, "Struts")
static int
osk_struts_init (OskStruts *odc, PyObject *args, PyObject *kwds)
{
return 0;
}
static void
osk_struts_dealloc (OskStruts *struts)
{
OSK_FINISH_DEALLOC (struts);
}
static PyObject *
osk_struts_set (PyObject *self, PyObject *args)
{
Display *dpy;
unsigned long xid;
unsigned long struts[12] = { 0, };
PyObject *obj, *seq, **items;
int i;
if (!PyArg_ParseTuple (args, "kO", &xid, &obj))
return NULL;
seq = PySequence_Fast (obj, "expected sequence type");
if (!seq)
return NULL;
if (PySequence_Fast_GET_SIZE (seq) != 12)
{
PyErr_SetString (PyExc_ValueError, "expected 12 values");
Py_DECREF (seq);
return NULL;
}
items = PySequence_Fast_ITEMS (seq);
for (i = 0; i < 12; i++, items++)
{
struts[i] = PyLong_AsUnsignedLongMask (*items);
if (PyErr_Occurred ())
{
Py_DECREF (seq);
return NULL;
}
if (struts[i] < 0)
{
PyErr_SetString (PyExc_ValueError, "expected value >= 0");
Py_DECREF (seq);
return NULL;
}
}
Py_DECREF (seq);
dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
gdk_error_trap_push ();
XChangeProperty (dpy, xid,
XInternAtom (dpy, "_NET_WM_STRUT", False),
XA_CARDINAL, 32, PropModeReplace,
(unsigned char *) &struts, 4);
XChangeProperty (dpy, xid,
XInternAtom (dpy, "_NET_WM_STRUT_PARTIAL", False),
XA_CARDINAL, 32, PropModeReplace,
(unsigned char *) &struts, 12);
gdk_error_trap_pop_ignored ();
Py_RETURN_NONE;
}
static PyObject *
osk_struts_clear (PyObject *self, PyObject *args)
{
Display *dpy;
unsigned long xid;
if (!PyArg_ParseTuple (args, "k", &xid))
return NULL;
dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
gdk_error_trap_push ();
XDeleteProperty (dpy, xid, XInternAtom (dpy, "_NET_WM_STRUT", False));
XDeleteProperty (dpy, xid, XInternAtom (dpy, "_NET_WM_STRUT_PARTIAL", False));
gdk_error_trap_pop_ignored ();
Py_RETURN_NONE;
}
static PyMethodDef osk_struts_methods[] = {
{ "set", osk_struts_set, METH_VARARGS, NULL },
{ "clear", osk_struts_clear, METH_VARARGS, NULL },
{ NULL, NULL, 0, NULL }
};
|