Mercurial > octave
annotate libinterp/corefcn/cdisplay.c @ 33624:e0c037a01fde default tip
redirect stdout and stderr into experimental terminal widget
* command-widget.cc (command_widget): open temp files for redirecting
stdout and stderr, setup a file system watcher for signals on changes
to these files;
(~command_widget): close and remove the temp. files;
(insert_interpreter_output): use the style as second argument
(print_stream): add new contents of temp. files for stdout and stderr
to the end of the terminal contents;
(notice_settings): set the terminal preferences to the new lexer of
the console;
(console): create and set new lexer;
(new_command_line): use prompt style for the prompt;
(execute_command): use second command line argument for the style;
(append_string): use style as second argument and style the added
text accordingly;
* command-widget.h (console) append_string with second argument for style,
(command_widget): now with destructor, new method print_stream,
insert_interpreter_output with second argument for style, new class
variables for temp. file descriptors and file system watcher
* console-lexer.cc/h: new lexer derived from QScintillas default lexer
for styling the terminal output, styles used so far: Default, Error,
and Prompt
* gui-preferences-cs.h: new constants for error and prompt colors
* libgui/src/module.mk: new files console_lexer.cc/h
* qt-interpreter-events.cc (display_exception): interpreter_output_signal
with second argument for the style, here Error style
* qt-interpreter-events.h: interpreter_output_signal with second
argument for the style
* terminal-dock-widget.h: interpreter_output_signal with second
argument for the style
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Sat, 25 May 2024 14:36:01 +0200 |
parents | 2e484f9f1f18 |
children |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
31706
diff
changeset
|
3 // Copyright (C) 2009-2024 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
18932
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
27 # include "config.h" |
18932
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 #endif |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
29 |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
30 #include <stdlib.h> |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 #if defined (OCTAVE_USE_WINDOWS_API) |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 #include <windows.h> |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
34 #elif defined (HAVE_FRAMEWORK_CARBON) |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
35 #include <Carbon/Carbon.h> |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 #elif defined (HAVE_X_WINDOWS) |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 #include <X11/Xlib.h> |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 #endif |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
40 #include "cdisplay.h" |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
41 |
20948
babc439a224f
* cdisplay.c: Add comment explaining existence of file.
John W. Eaton <jwe@octave.org>
parents:
18932
diff
changeset
|
42 // Programming Note: This file exists so that we can hide system |
babc439a224f
* cdisplay.c: Add comment explaining existence of file.
John W. Eaton <jwe@octave.org>
parents:
18932
diff
changeset
|
43 // header files that make heavy use of macros and C-style casts in a C |
babc439a224f
* cdisplay.c: Add comment explaining existence of file.
John W. Eaton <jwe@octave.org>
parents:
18932
diff
changeset
|
44 // language file and avoid warnings about using old-style casts in C++. |
20949
e456327188f9
* cdisplay.c: Additional programming notes.
John W. Eaton <jwe@octave.org>
parents:
20948
diff
changeset
|
45 // Additionally, on OS X systems, including the Carbon.h header file |
e456327188f9
* cdisplay.c: Additional programming notes.
John W. Eaton <jwe@octave.org>
parents:
20948
diff
changeset
|
46 // results in the declaration of a "panic" function that conflicts with |
e456327188f9
* cdisplay.c: Additional programming notes.
John W. Eaton <jwe@octave.org>
parents:
20948
diff
changeset
|
47 // Octave's global panic function, so Carbon.h can't be included in any |
e456327188f9
* cdisplay.c: Additional programming notes.
John W. Eaton <jwe@octave.org>
parents:
20948
diff
changeset
|
48 // file that also includes Octave's error.h header file. |
e456327188f9
* cdisplay.c: Additional programming notes.
John W. Eaton <jwe@octave.org>
parents:
20948
diff
changeset
|
49 |
e456327188f9
* cdisplay.c: Additional programming notes.
John W. Eaton <jwe@octave.org>
parents:
20948
diff
changeset
|
50 // Please do NOT eliminate this file and move code from here to |
e456327188f9
* cdisplay.c: Additional programming notes.
John W. Eaton <jwe@octave.org>
parents:
20948
diff
changeset
|
51 // display.cc. |
20948
babc439a224f
* cdisplay.c: Add comment explaining existence of file.
John W. Eaton <jwe@octave.org>
parents:
18932
diff
changeset
|
52 |
18932
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
53 const char * |
23746
7f176909ab86
move display_info class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
54 octave_get_display_info (const char *dpy_name, int *ht, int *wd, int *dp, |
7f176909ab86
move display_info class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
55 double *rx, double *ry, int *dpy_avail) |
18932
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
56 { |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
57 const char *msg = NULL; |
18932
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
58 |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
59 *dpy_avail = 0; |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
60 |
27181
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
61 double ht_mm = 0.0; |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
62 double wd_mm = 0.0; |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
63 |
18932
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
64 #if defined (OCTAVE_USE_WINDOWS_API) |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
65 |
24118
f87c9f5c0f43
maint: silence several compiler warnings when building for Windows
Mike Miller <mtmiller@octave.org>
parents:
23746
diff
changeset
|
66 octave_unused_parameter (dpy_name); |
f87c9f5c0f43
maint: silence several compiler warnings when building for Windows
Mike Miller <mtmiller@octave.org>
parents:
23746
diff
changeset
|
67 |
18932
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
68 HDC hdc = GetDC (0); |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
69 |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
70 if (hdc) |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
71 { |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
72 *dp = GetDeviceCaps (hdc, BITSPIXEL); |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
73 |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
74 *ht = GetDeviceCaps (hdc, VERTRES); |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
75 *wd = GetDeviceCaps (hdc, HORZRES); |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
76 |
27181
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
77 ht_mm = GetDeviceCaps (hdc, VERTSIZE); |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
78 wd_mm = GetDeviceCaps (hdc, HORZSIZE); |
18932
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
79 |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
80 *dpy_avail = 1; |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
81 } |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
82 else |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
83 msg = "no graphical display found"; |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
84 |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
85 #elif defined (HAVE_FRAMEWORK_CARBON) |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
86 |
24118
f87c9f5c0f43
maint: silence several compiler warnings when building for Windows
Mike Miller <mtmiller@octave.org>
parents:
23746
diff
changeset
|
87 octave_unused_parameter (dpy_name); |
f87c9f5c0f43
maint: silence several compiler warnings when building for Windows
Mike Miller <mtmiller@octave.org>
parents:
23746
diff
changeset
|
88 |
18932
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
89 CGDirectDisplayID display = CGMainDisplayID (); |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
90 |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
91 if (display) |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
92 { |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
93 #if defined (HAVE_CARBON_CGDISPLAYBITSPERPIXEL) |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
94 |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
95 *dp = CGDisplayBitsPerPixel (display); |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
96 |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
97 #else |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
98 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
99 /* FIXME: This will only work for MacOS > 10.5. For earlier versions |
18932
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
100 this code is not needed (use CGDisplayBitsPerPixel instead). */ |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
101 |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
102 CGDisplayModeRef mode = CGDisplayCopyDisplayMode (display); |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
103 CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding (mode); |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
104 |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
105 if (CFStringCompare (pixelEncoding, CFSTR (IO32BitDirectPixels), 0) == 0) |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
106 *dp = 32; |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
107 else if (CFStringCompare (pixelEncoding, |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
108 CFSTR (IO16BitDirectPixels), 0) == 0) |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
109 *dp = 16; |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
110 else |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
111 *dp = 8; |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
112 |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
113 #endif |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
114 |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
115 *ht = CGDisplayPixelsHigh (display); |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
116 *wd = CGDisplayPixelsWide (display); |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
117 |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
118 CGSize sz_mm = CGDisplayScreenSize (display); |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
119 |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
120 /* For MacOS >= 10.6, CGSize is a struct keeping 2 CGFloat |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
121 values, but the CGFloat typedef is not present on older |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
122 systems, so use double instead. */ |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
123 |
27181
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
124 ht_mm = sz_mm.height; |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
125 wd_mm = sz_mm.width; |
18932
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
126 |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
127 *dpy_avail = 1; |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
128 } |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
129 else |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
130 msg = "no graphical display found"; |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
131 |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
132 #elif defined (HAVE_X_WINDOWS) |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
133 |
23746
7f176909ab86
move display_info class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
134 /* If dpy_name is NULL, XopenDisplay will look for DISPLAY in the |
7f176909ab86
move display_info class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
135 environment. */ |
18932
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
136 |
23746
7f176909ab86
move display_info class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
137 Display *display = XOpenDisplay (dpy_name); |
18932
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
138 |
23746
7f176909ab86
move display_info class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
139 if (display) |
7f176909ab86
move display_info class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
140 { |
7f176909ab86
move display_info class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
141 Screen *screen = DefaultScreenOfDisplay (display); |
18932
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
142 |
23746
7f176909ab86
move display_info class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
143 if (screen) |
7f176909ab86
move display_info class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
144 { |
7f176909ab86
move display_info class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
145 *dp = DefaultDepthOfScreen (screen); |
18932
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
146 |
23746
7f176909ab86
move display_info class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
147 *ht = HeightOfScreen (screen); |
7f176909ab86
move display_info class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
148 *wd = WidthOfScreen (screen); |
18932
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
149 |
23746
7f176909ab86
move display_info class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
150 int screen_number = XScreenNumberOfScreen (screen); |
18932
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
151 |
27181
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
152 ht_mm = DisplayHeightMM (display, screen_number); |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
153 wd_mm = DisplayWidthMM (display, screen_number); |
27275
1565c39aa940
don't show display warning in display_info initialization (bug #56651)
John W. Eaton <jwe@octave.org>
parents:
27181
diff
changeset
|
154 |
1565c39aa940
don't show display warning in display_info initialization (bug #56651)
John W. Eaton <jwe@octave.org>
parents:
27181
diff
changeset
|
155 *dpy_avail = 1; |
18932
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
156 } |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
157 else |
23746
7f176909ab86
move display_info class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
158 msg = "X11 display has no default screen"; |
7f176909ab86
move display_info class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
159 |
7f176909ab86
move display_info class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
160 XCloseDisplay (display); |
18932
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
161 } |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
162 else |
23746
7f176909ab86
move display_info class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
163 msg = "unable to open X11 DISPLAY"; |
18932
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
164 |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
165 #else |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
166 |
24118
f87c9f5c0f43
maint: silence several compiler warnings when building for Windows
Mike Miller <mtmiller@octave.org>
parents:
23746
diff
changeset
|
167 octave_unused_parameter (dpy_name); |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
168 octave_unused_parameter (ht); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
169 octave_unused_parameter (wd); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
170 octave_unused_parameter (dp); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
171 octave_unused_parameter (rx); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
172 octave_unused_parameter (ry); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
173 |
18932
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
174 msg = "no graphical display found"; |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
175 |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
176 #endif |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
177 |
27181
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
178 if (*dpy_avail) |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
179 { |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
180 if (wd_mm == 0 || ht_mm == 0) |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
181 { |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
182 msg = "screen width or height reported to be zero"; |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
183 |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
184 // Sizes reported as zero have been found on some systems. |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
185 // For example, X/Wayland running inside virtualbox. |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
186 |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
187 // Guess a DPI. |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
188 |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
189 *rx = 96.0; |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
190 *ry = 96.0; |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
191 } |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
192 else |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
193 { |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
194 *rx = *wd * 25.4 / wd_mm; |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
195 *ry = *ht * 25.4 / ht_mm; |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
196 } |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
197 } |
5754e8d8199a
guess screen dpi if screen size is reported to be zero
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
198 |
18932
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
199 return msg; |
edc4791fbcb2
avoid some old-style cast warnings
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
200 } |