[3370] | 1 | //roarx11.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[5823] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2013 |
---|
[3370] | 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 |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[3370] | 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 | |
---|
[3371] | 38 | struct roar_x11_connection * roar_x11_connect(char * display) { |
---|
| 39 | #ifdef ROAR_HAVE_LIBX11 |
---|
[3375] | 40 | struct roar_libroar_config * config = roar_libroar_get_config(); |
---|
[3371] | 41 | struct roar_x11_connection * con; |
---|
| 42 | |
---|
[3375] | 43 | if ( display == NULL ) |
---|
| 44 | display = config->x11.display; |
---|
| 45 | |
---|
[3371] | 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 | |
---|
[3487] | 54 | con->close = 1; |
---|
| 55 | |
---|
| 56 | return con; |
---|
| 57 | #else |
---|
| 58 | return NULL; |
---|
| 59 | #endif |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | struct 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 | |
---|
[3371] | 75 | return con; |
---|
| 76 | #else |
---|
| 77 | return NULL; |
---|
| 78 | #endif |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | int roar_x11_disconnect(struct roar_x11_connection * con) { |
---|
| 82 | #ifdef ROAR_HAVE_LIBX11 |
---|
[3487] | 83 | int ret = 0; |
---|
[3371] | 84 | |
---|
| 85 | if ( con == NULL ) |
---|
| 86 | return -1; |
---|
| 87 | |
---|
[3487] | 88 | if ( con->close ) |
---|
| 89 | ret = XCloseDisplay(con->display); |
---|
[3371] | 90 | |
---|
| 91 | roar_mm_free(con); |
---|
| 92 | |
---|
| 93 | return ret; |
---|
| 94 | #else |
---|
| 95 | return -1; |
---|
| 96 | #endif |
---|
| 97 | } |
---|
| 98 | |
---|
[3627] | 99 | int roar_x11_flush(struct roar_x11_connection * con) { |
---|
| 100 | #ifdef ROAR_HAVE_LIBX11 |
---|
| 101 | if ( con == NULL ) |
---|
| 102 | return -1; |
---|
| 103 | |
---|
| 104 | return XFlush(con->display); |
---|
| 105 | #else |
---|
| 106 | return -1; |
---|
| 107 | #endif |
---|
| 108 | } |
---|
| 109 | |
---|
[3371] | 110 | int roar_x11_set_prop(struct roar_x11_connection * con, const char * key, const char * val) { |
---|
| 111 | #ifdef ROAR_HAVE_LIBX11 |
---|
| 112 | Atom a; |
---|
| 113 | |
---|
| 114 | if ( con == NULL ) |
---|
| 115 | return -1; |
---|
| 116 | |
---|
| 117 | a = XInternAtom(con->display, key, False); |
---|
| 118 | |
---|
| 119 | XChangeProperty(con->display, RootWindow(con->display, 0), a, XA_STRING, 8, PropModeReplace, (const unsigned char*) val, strlen(val)+1); |
---|
| 120 | |
---|
| 121 | return 0; |
---|
| 122 | #else |
---|
| 123 | return -1; |
---|
| 124 | #endif |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | int roar_x11_delete_prop(struct roar_x11_connection * con, const char * key) { |
---|
| 128 | #ifdef ROAR_HAVE_LIBX11 |
---|
| 129 | Atom a; |
---|
| 130 | if ( con == NULL ) |
---|
| 131 | return -1; |
---|
| 132 | |
---|
| 133 | a = XInternAtom(con->display, key, False); |
---|
| 134 | XDeleteProperty(con->display, RootWindow(con->display, 0), a); |
---|
| 135 | |
---|
| 136 | return 0; |
---|
| 137 | #else |
---|
| 138 | return -1; |
---|
| 139 | #endif |
---|
| 140 | } |
---|
| 141 | |
---|
[3372] | 142 | char * roar_x11_get_prop(struct roar_x11_connection * con, const char * key) { |
---|
[3474] | 143 | #ifdef ROAR_HAVE_LIBX11 |
---|
[3372] | 144 | unsigned long nitems; |
---|
| 145 | unsigned long nbytes_after; |
---|
| 146 | unsigned char * prop = NULL; |
---|
| 147 | char * ret = NULL; |
---|
| 148 | int actual_format; |
---|
| 149 | Atom actual_type; |
---|
| 150 | Atom a; |
---|
| 151 | |
---|
| 152 | a = XInternAtom(con->display, key, False); |
---|
| 153 | |
---|
| 154 | if ( XGetWindowProperty(con->display, RootWindow(con->display, 0), a, |
---|
| 155 | 0, 256, False, XA_STRING, &actual_type, |
---|
| 156 | &actual_format, &nitems, &nbytes_after, &prop) != Success ) { |
---|
| 157 | if ( prop != NULL ) |
---|
| 158 | XFree(prop); |
---|
| 159 | |
---|
| 160 | return NULL; |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | if ( prop == NULL ) |
---|
| 164 | return NULL; |
---|
| 165 | |
---|
| 166 | if (actual_type != XA_STRING) { |
---|
| 167 | XFree(prop); |
---|
| 168 | |
---|
| 169 | return NULL; |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | ret = roar_mm_malloc(nitems+1); |
---|
| 173 | |
---|
| 174 | memcpy(ret, prop, nitems); |
---|
| 175 | ret[nitems] = 0; |
---|
| 176 | |
---|
| 177 | XFree(prop); |
---|
| 178 | |
---|
| 179 | return ret; |
---|
[3474] | 180 | #else |
---|
| 181 | return NULL; |
---|
| 182 | #endif |
---|
[3372] | 183 | } |
---|
| 184 | |
---|
[3370] | 185 | //ll |
---|