Mercurial > octave-nkf
annotate src/display-available.c @ 20654:b65888ec820e draft default tip gccjit
dmalcom gcc jit import
author | Stefan Mahr <dac922@gmx.de> |
---|---|
date | Fri, 27 Feb 2015 16:59:36 +0100 |
parents | 299fe39163a2 |
children |
rev | line source |
---|---|
19819
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1 /* |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
2 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
3 Copyright (C) 2012-2015 John W. Eaton |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
4 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
5 This file is part of Octave. |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
6 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
7 Octave is free software; you can redistribute it and/or modify it |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
8 under the terms of the GNU General Public License as published by the |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
9 Free Software Foundation; either version 3 of the License, or (at your |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
10 option) any later version. |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
11 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
15 for more details. |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
16 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
18 along with Octave; see the file COPYING. If not, see |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
19 <http://www.gnu.org/licenses/>. |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
20 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
21 */ |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
22 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
23 #ifdef HAVE_CONFIG_H |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
24 #include <config.h> |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 #endif |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 #include <stdlib.h> |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
29 #if defined (OCTAVE_USE_WINDOWS_API) |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
30 #include <windows.h> |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 #elif defined (HAVE_FRAMEWORK_CARBON) |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 #include <Carbon/Carbon.h> |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 #elif defined (HAVE_X_WINDOWS) |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
34 #include <X11/Xlib.h> |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
35 #endif |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 #include "display-available.h" |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 const char * |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
40 display_available (int *dpy_avail) |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
41 { |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
42 *dpy_avail = 0; |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
43 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 const char *err_msg = ""; |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
45 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
46 #if defined (OCTAVE_USE_WINDOWS_API) |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
47 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
48 HDC hdc = GetDC (0); |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
49 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
50 if (hdc) |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
51 *dpy_avail = 1; |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
52 else |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
53 err_msg = "no graphical display found"; |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
54 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
55 #elif defined (HAVE_FRAMEWORK_CARBON) |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
56 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
57 CGDirectDisplayID display = CGMainDisplayID (); |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
58 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
59 if (display) |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
60 *dpy_avail = 1; |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
61 else |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
62 err_msg = "no graphical display found"; |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
63 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
64 #elif defined (HAVE_X_WINDOWS) |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
65 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
66 const char *display_name = getenv ("DISPLAY"); |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
67 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
68 if (display_name && *display_name) |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
69 { |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
70 Display *display = XOpenDisplay (display_name); |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
71 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
72 if (display) |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
73 { |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
74 Screen *screen = DefaultScreenOfDisplay (display); |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
75 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
76 if (! screen) |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
77 err_msg = "X11 display has no default screen"; |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
78 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
79 XCloseDisplay (display); |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
80 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
81 *dpy_avail = 1; |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
82 } |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
83 else |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
84 err_msg = "unable to open X11 DISPLAY"; |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
85 } |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
86 else |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
87 err_msg = "X11 DISPLAY environment variable not set"; |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
88 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
89 #else |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
90 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
91 err_msg = "no graphical display found"; |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
92 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
93 #endif |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
94 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
95 return err_msg; |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
96 } |