source: roaraudio/libroar/roarx11.c @ 3487:be2ecd9ae926

Last change on this file since 3487:be2ecd9ae926 was 3487:be2ecd9ae926, checked in by phi, 14 years ago

updated x11 interface a bit

File size: 4.0 KB
Line 
1//roarx11.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010
5 *
6 *  This file is part of libroar a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  libroar is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 *  NOTE for everyone want's to change something and send patches:
24 *  read README and HACKING! There a addition information on
25 *  the license of this document you need to read before you send
26 *  any patches.
27 *
28 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
29 *  or libpulse*:
30 *  The libs libroaresd, libroararts and libroarpulse link this lib
31 *  and are therefore GPL. Because of this it may be illigal to use
32 *  them with any software that uses libesd, libartsc or libpulse*.
33 */
34
35#include "libroar.h"
36
37struct roar_x11_connection * roar_x11_connect(char * display) {
38#ifdef ROAR_HAVE_LIBX11
39 struct roar_libroar_config * config = roar_libroar_get_config();
40 struct roar_x11_connection * con;
41
42 if ( display == NULL )
43  display = config->x11.display;
44
45 if ( (con = roar_mm_malloc(sizeof(struct roar_x11_connection))) == NULL )
46  return NULL;
47
48 if ( (con->display = XOpenDisplay(display)) == NULL ) {
49  roar_mm_free(con);
50  return NULL;
51 }
52
53 con->close = 1;
54
55 return con;
56#else
57 return NULL;
58#endif
59}
60
61struct roar_x11_connection * roar_x11_connect_display(_ROAR_X11_DISPLAY * display) {
62#ifdef ROAR_HAVE_LIBX11
63 struct roar_x11_connection * con;
64
65 if ( display == NULL )
66  return NULL;
67
68 if ( (con = roar_mm_malloc(sizeof(struct roar_x11_connection))) == NULL )
69  return NULL;
70
71 con->close   = 0;
72 con->display = display;
73
74 return con;
75#else
76 return NULL;
77#endif
78}
79
80int roar_x11_disconnect(struct roar_x11_connection * con) {
81#ifdef ROAR_HAVE_LIBX11
82 int ret = 0;
83
84 if ( con == NULL )
85  return -1;
86
87 if ( con->close )
88  ret = XCloseDisplay(con->display);
89
90 roar_mm_free(con);
91
92 return ret;
93#else
94 return -1;
95#endif
96}
97
98int roar_x11_set_prop(struct roar_x11_connection * con, const char * key, const char * val) {
99#ifdef ROAR_HAVE_LIBX11
100 Atom a;
101
102 if ( con == NULL )
103  return -1;
104
105 a = XInternAtom(con->display, key, False);
106
107 XChangeProperty(con->display, RootWindow(con->display, 0), a, XA_STRING, 8, PropModeReplace, (const unsigned char*) val, strlen(val)+1);
108
109 return 0;
110#else
111 return -1;
112#endif
113}
114
115int roar_x11_delete_prop(struct roar_x11_connection * con, const char * key) {
116#ifdef ROAR_HAVE_LIBX11
117 Atom a;
118 if ( con == NULL )
119  return -1;
120
121 a = XInternAtom(con->display, key, False);
122 XDeleteProperty(con->display, RootWindow(con->display, 0), a);
123
124 return 0;
125#else
126 return -1;
127#endif
128}
129
130char * roar_x11_get_prop(struct roar_x11_connection * con, const char * key) {
131#ifdef ROAR_HAVE_LIBX11
132 unsigned long   nitems;
133 unsigned long   nbytes_after;
134 unsigned char * prop = NULL;
135 char          * ret = NULL;
136 int             actual_format;
137 Atom            actual_type;
138 Atom            a;
139
140 a = XInternAtom(con->display, key, False);
141
142 if ( XGetWindowProperty(con->display, RootWindow(con->display, 0), a,
143                         0, 256, False, XA_STRING, &actual_type,
144                         &actual_format, &nitems, &nbytes_after, &prop) != Success ) {
145  if ( prop != NULL )
146   XFree(prop);
147
148  return NULL;
149 }
150
151 if ( prop == NULL )
152  return NULL;
153
154 if (actual_type != XA_STRING) {
155  XFree(prop);
156
157  return NULL;
158 }
159
160 ret = roar_mm_malloc(nitems+1);
161
162 memcpy(ret, prop, nitems);
163 ret[nitems] = 0;
164
165 XFree(prop);
166
167 return ret;
168#else
169 return NULL;
170#endif
171}
172
173//ll
Note: See TracBrowser for help on using the repository browser.