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