source: roaraudio/libroar/roarx11.c @ 3517:1a3218a3fc5b

Last change on this file since 3517:1a3218a3fc5b was 3517:1a3218a3fc5b, checked in by phi, 14 years ago

updated license headers, FSF moved office

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, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 *  NOTE for everyone want's to change something and send patches:
25 *  read README and HACKING! There a addition information on
26 *  the license of this document you need to read before you send
27 *  any patches.
28 *
29 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
30 *  or libpulse*:
31 *  The libs libroaresd, libroararts and libroarpulse link this lib
32 *  and are therefore GPL. Because of this it may be illigal to use
33 *  them with any software that uses libesd, libartsc or libpulse*.
34 */
35
36#include "libroar.h"
37
38struct roar_x11_connection * roar_x11_connect(char * display) {
39#ifdef ROAR_HAVE_LIBX11
40 struct roar_libroar_config * config = roar_libroar_get_config();
41 struct roar_x11_connection * con;
42
43 if ( display == NULL )
44  display = config->x11.display;
45
46 if ( (con = roar_mm_malloc(sizeof(struct roar_x11_connection))) == NULL )
47  return NULL;
48
49 if ( (con->display = XOpenDisplay(display)) == NULL ) {
50  roar_mm_free(con);
51  return NULL;
52 }
53
54 con->close = 1;
55
56 return con;
57#else
58 return NULL;
59#endif
60}
61
62struct roar_x11_connection * roar_x11_connect_display(_ROAR_X11_DISPLAY * display) {
63#ifdef ROAR_HAVE_LIBX11
64 struct roar_x11_connection * con;
65
66 if ( display == NULL )
67  return NULL;
68
69 if ( (con = roar_mm_malloc(sizeof(struct roar_x11_connection))) == NULL )
70  return NULL;
71
72 con->close   = 0;
73 con->display = display;
74
75 return con;
76#else
77 return NULL;
78#endif
79}
80
81int roar_x11_disconnect(struct roar_x11_connection * con) {
82#ifdef ROAR_HAVE_LIBX11
83 int ret = 0;
84
85 if ( con == NULL )
86  return -1;
87
88 if ( con->close )
89  ret = XCloseDisplay(con->display);
90
91 roar_mm_free(con);
92
93 return ret;
94#else
95 return -1;
96#endif
97}
98
99int roar_x11_set_prop(struct roar_x11_connection * con, const char * key, const char * val) {
100#ifdef ROAR_HAVE_LIBX11
101 Atom a;
102
103 if ( con == NULL )
104  return -1;
105
106 a = XInternAtom(con->display, key, False);
107
108 XChangeProperty(con->display, RootWindow(con->display, 0), a, XA_STRING, 8, PropModeReplace, (const unsigned char*) val, strlen(val)+1);
109
110 return 0;
111#else
112 return -1;
113#endif
114}
115
116int roar_x11_delete_prop(struct roar_x11_connection * con, const char * key) {
117#ifdef ROAR_HAVE_LIBX11
118 Atom a;
119 if ( con == NULL )
120  return -1;
121
122 a = XInternAtom(con->display, key, False);
123 XDeleteProperty(con->display, RootWindow(con->display, 0), a);
124
125 return 0;
126#else
127 return -1;
128#endif
129}
130
131char * roar_x11_get_prop(struct roar_x11_connection * con, const char * key) {
132#ifdef ROAR_HAVE_LIBX11
133 unsigned long   nitems;
134 unsigned long   nbytes_after;
135 unsigned char * prop = NULL;
136 char          * ret = NULL;
137 int             actual_format;
138 Atom            actual_type;
139 Atom            a;
140
141 a = XInternAtom(con->display, key, False);
142
143 if ( XGetWindowProperty(con->display, RootWindow(con->display, 0), a,
144                         0, 256, False, XA_STRING, &actual_type,
145                         &actual_format, &nitems, &nbytes_after, &prop) != Success ) {
146  if ( prop != NULL )
147   XFree(prop);
148
149  return NULL;
150 }
151
152 if ( prop == NULL )
153  return NULL;
154
155 if (actual_type != XA_STRING) {
156  XFree(prop);
157
158  return NULL;
159 }
160
161 ret = roar_mm_malloc(nitems+1);
162
163 memcpy(ret, prop, nitems);
164 ret[nitems] = 0;
165
166 XFree(prop);
167
168 return ret;
169#else
170 return NULL;
171#endif
172}
173
174//ll
Note: See TracBrowser for help on using the repository browser.