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