Annotation of freem/src/ssvn_display.c, revision 1.1.1.1
1.1 snw 1: /*
2: * *
3: * * *
4: * * *
5: * ***************
6: * * * * *
7: * * MUMPS *
8: * * * * *
9: * ***************
10: * * *
11: * * *
12: * *
13: *
14: * ssvn_display.c
15: * ^$DISPLAY ssv
16: *
17: *
18: * Author: Serena Willis <jpw@coherent-logic.com>
19: * Copyright (C) 1998 MUG Deutschland
20: * Copyright (C) 2020 Coherent Logic Development LLC
21: *
22: *
23: * This file is part of FreeM.
24: *
25: * FreeM is free software: you can redistribute it and/or modify
26: * it under the terms of the GNU Affero Public License as published by
27: * the Free Software Foundation, either version 3 of the License, or
28: * (at your option) any later version.
29: *
30: * FreeM is distributed in the hope that it will be useful,
31: * but WITHOUT ANY WARRANTY; without even the implied warranty of
32: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33: * GNU Affero Public License for more details.
34: *
35: * You should have received a copy of the GNU Affero Public License
36: * along with FreeM. If not, see <https://www.gnu.org/licenses/>.
37: *
38: **/
39:
40: #include <stdio.h>
41: #include <stdlib.h>
42: #include <string.h>
43: #include <errno.h>
44: #include <ctype.h>
45: #include <unistd.h>
46:
47: #include "mpsdef.h"
48:
49: #if defined(HAVE_MWAPI_MOTIF)
50: #include <limits.h>
51: //#include <gtk/gtk.h>
52: #include <X11/Xlib.h>
53: //#include <glib.h>
54: //#include <pango/pangocairo.h>
55:
56: #include "mref.h"
57:
58: int ssvn_display_initialized = 0;
59: char clipboard_buffer[256];
60:
61: void ssvn_display_update(void)
62: {
63: int i;
64: int j;
65: int k;
66:
67: int count_screens;
68: char k_buf[512];
69: char d_buf[512];
70:
71: char display_name[50];
72:
73: Display *display;
74: Screen *screen;
75:
76: // PangoFontFamily **families;
77: // int n_families;
78: // PangoFontMap *font_map;
79:
80: char *result;
81: unsigned long ressize, restail;
82: int resbits;
83: Atom bufid;
84: Atom fmtid;
85: Atom propid;
86: Atom incrid;
87: XEvent event;
88: unsigned long color;
89: Window window;
90:
91: memset (clipboard_buffer, 0, sizeof (clipboard_buffer));
92:
93: display = XOpenDisplay (NULL);
94:
95: if (display == NULL) return;
96:
97: count_screens = ScreenCount (display);
98:
99: color = BlackPixel (display, DefaultScreen(display));
100: window = XCreateSimpleWindow (display, DefaultRootWindow(display), 0,0, 1,1, 0, color, color);
101: bufid = XInternAtom (display, "CLIPBOARD", False);
102: fmtid = XInternAtom (display, "STRING", False);
103: propid = XInternAtom (display, "XSEL_DATA", False);
104: incrid = XInternAtom (display, "INCR", False);
105: // font_map = pango_cairo_font_map_get_default ();
106: // pango_font_map_list_families (font_map, &families, &n_families);
107:
108: XConvertSelection (display, bufid, fmtid, propid, window, CurrentTime);
109:
110: do {
111: XNextEvent (display, &event);
112: } while (event.type != SelectionNotify || event.xselection.selection != bufid);
113:
114: if (event.xselection.property) {
115: XGetWindowProperty (display, window, propid, 0, LONG_MAX/4, False, AnyPropertyType,
116: &fmtid, &resbits, &ressize, &restail, (unsigned char**)&result);
117:
118: if (fmtid != incrid) {
119: snprintf (clipboard_buffer, (ressize > 254 ? 254 : ressize), "%s", result);
120: stcnv_c2m (clipboard_buffer);
121: clipboard_buffer[255] = '\201';
122: }
123: else {
124: clipboard_buffer[0] = '\201';
125: }
126:
127: XFree (result);
128: }
129:
130: for (int i = 0; i < count_screens; ++i) {
131: screen = ScreenOfDisplay (display, i);
132:
133: snprintf (display_name, 49, "%d", i);
134:
135: snprintf (k_buf, 512 - 1, "^$DISPLAY\202%s\202PLATFORM\201", display_name);
136: symtab (set_sym, k_buf, "X/MOTIF,3\201");
137:
138: /*
139: snprintf (k_buf, 512 - 1, "^$DISPLAY\202%s\202CLIPBOARD\201", display_name);
140: symtab (set_sym, k_buf, clipboard_buffer);
141: */
142: snprintf (k_buf, 512 - 1, "^$DISPLAY\202%s\202SIZE\201", display_name);
143: snprintf (d_buf, 512 - 1, "%d,%d\201", screen->width, screen->height);
144: symtab (set_sym, k_buf, d_buf);
145:
146: snprintf (k_buf, 512 - 1, "^$DISPLAY\202%s\202SPECTRUM\201", display_name);
147: snprintf (d_buf, 512 - 1, "%d\201", 16777216L);
148: symtab (set_sym, k_buf, d_buf);
149:
150: snprintf (k_buf, 512 - 1, "^$DISPLAY\202%s\202COLORTYPE\201", display_name);
151: snprintf (d_buf, 512 - 1, "COLOR\201");
152: symtab (set_sym, k_buf, d_buf);
153:
154: snprintf (k_buf, 512 - 1, "^$DISPLAY\202%s\202UNITS\201", display_name);
155: snprintf (d_buf, 512 - 1, "PIXEL\201");
156: symtab (set_sym, k_buf, d_buf);
157:
158: #if 0
159: if (!ssvn_display_initialized) {
160:
161: // printf ("mwapi-gtk: enumerating system fonts... ");
162: for (j = 0; j < n_families; j++) {
163: PangoFontFamily *family = families[j];
164: const char *family_name;
165:
166: family_name = pango_font_family_get_name (family);
167:
168:
169: snprintf (k_buf, 512 - 1, "^$DISPLAY\202%s\202TYPEFACE\202%s\202%d\201", display_name, family_name, 0);
170: snprintf (d_buf, 512 - 1, "\201");
171: symtab (set_sym, k_buf, d_buf);
172:
173: /*
174: for (k = 8; k <= 72; k += 2) {
175: snprintf (k_buf, 512 - 1, "^$DISPLAY\202%s\202TYPEFACE\202%s\202%d\201", display_name, family_name, k);
176: snprintf (d_buf, 512 - 1, "\201");
177: symtab (set_sym, k_buf, d_buf);
178: }
179: */
180:
181: }
182: // printf ("%d font families discovered\r\n", n_families);
183:
184: }
185: #endif
186:
187:
188: }
189:
190: // g_free (families);
191:
192: if (!ssvn_display_initialized) {
193: ssvn_display_initialized = 1;
194: }
195:
196: XCloseDisplay (display);
197:
198: return;
199: }
200:
201: void ssvn_display(short action, char *key, char *data)
202: {
203: int i;
204:
205: freem_ref_t *r = (freem_ref_t *) malloc (sizeof (freem_ref_t));
206: NULLPTRCHK(r,"ssvn_display");
207:
208: char *dbuf = (char *) malloc (255 * sizeof (char));
209: NULLPTRCHK(dbuf,"ssvn_display");
210:
211: mref_init (r, MREF_RT_SSV, "^$DISPLAY");
212: internal_to_mref (r, key);
213:
214: if (r->subscript_count < 2) {
215: merr_raise (INVREF);
216: goto done;
217: }
218:
219: for (i = 0; i < strlen (r->subscripts[1]); i++) r->subscripts[1][i] = toupper (r->subscripts[1][i]);
220:
221: switch (action) {
222:
223: case fra_query:
224: case bigquery:
225: case dat:
226: case fra_order:
227:
228: if (strcmp (mref_get_subscript (r, 1), "CLIPBOARD") == 0) {
229: merr_raise (INVREF);
230: goto done;
231: }
232:
233: symtab (action, key, data);
234: break;
235:
236: case get_sym:
237:
238: if (strcmp (mref_get_subscript (r, 1), "CLIPBOARD") == 0) {
239:
240: }
241:
242: ssvn_display_update ();
243: symtab (action, key, data);
244:
245: break;
246:
247:
248: default:
249: merr_raise (INVREF);
250: break;
251:
252: }
253:
254: done:
255:
256: free (r);
257: free (dbuf);
258:
259: return;
260:
261: }
262: #else
263: void ssvn_display_update(void)
264: {
265: return;
266: }
267:
268: void ssvn_display(short action, char *key, char *data)
269: {
270: merr_raise (M38);
271: *data = EOL;
272: return;
273: }
274: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>