FreeCalypso > hg > freecalypso-ui-dev
comparison lcdemu/window.c @ 0:e7f1035f10d4
lcdemu: initial import from freecalypso-tools
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 14 Mar 2018 18:16:45 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e7f1035f10d4 |
---|---|
1 /* | |
2 * LCDemu based on HECterm by the same author | |
3 * X11 window creation functions | |
4 */ | |
5 | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 #include <strings.h> | |
10 #include <X11/Xlib.h> | |
11 #include <X11/Xresource.h> | |
12 #include <X11/Xutil.h> | |
13 #include "globals.h" | |
14 | |
15 extern char *xrm_lookup(); | |
16 | |
17 create_our_window() | |
18 { | |
19 XrmQuark instquarks[3], classquarks[3]; | |
20 register char *cp; | |
21 register int i, geomask; | |
22 int pixwidth, pixheight, xpos, ypos; | |
23 XSetWindowAttributes xswa; | |
24 u_long xswamask; | |
25 XColor bdcolor; | |
26 XClassHint xclasshint; | |
27 XWMHints wmhints; | |
28 XSizeHints wm_normal_hints; | |
29 | |
30 /* Determine our geometry */ | |
31 instquarks[0] = xrmquark_topinstance; | |
32 classquarks[0] = xrmquark_topclass; | |
33 classquarks[1] = instquarks[1] = XrmStringToQuark("geometry"); | |
34 instquarks[2] = classquarks[2] = NULLQUARK; | |
35 cp = xrm_lookup(instquarks, classquarks); | |
36 if (cp) { | |
37 geomask = XParseGeometry(cp, &xpos, &ypos, &pixwidth, | |
38 &pixheight); | |
39 free(cp); | |
40 } else | |
41 geomask = 0; | |
42 if (!(geomask & WidthValue)) | |
43 pixwidth = 176; | |
44 if (!(geomask & HeightValue)) | |
45 pixheight = 220; | |
46 if (!(geomask & XValue)) | |
47 xpos = 0; | |
48 else if (geomask & XNegative) | |
49 xpos += DisplayWidth(mydisplay, DefaultScreen(mydisplay)) - | |
50 pixwidth; | |
51 if (!(geomask & YValue)) | |
52 ypos = 0; | |
53 else if (geomask & YNegative) | |
54 ypos += DisplayHeight(mydisplay, DefaultScreen(mydisplay)) - | |
55 pixheight; | |
56 /* fill out XSetWindowAttributes */ | |
57 xswa.event_mask = 0; /* not interested in any events */ | |
58 xswamask = CWEventMask; | |
59 /* border color */ | |
60 classquarks[1] = instquarks[1] = XrmStringToQuark("borderColor"); | |
61 cp = xrm_lookup(instquarks, classquarks); | |
62 if (cp) { | |
63 i = XParseColor(mydisplay, DefaultColormap(mydisplay, | |
64 DefaultScreen(mydisplay)), cp, &bdcolor); | |
65 free(cp); | |
66 if (i) { | |
67 i = XAllocColor(mydisplay, DefaultColormap(mydisplay, | |
68 DefaultScreen(mydisplay)), &bdcolor); | |
69 if (i) { | |
70 xswa.border_pixel = bdcolor.pixel; | |
71 xswamask |= CWBorderPixel; | |
72 } | |
73 } | |
74 } | |
75 /* border width */ | |
76 classquarks[1] = instquarks[1] = XrmStringToQuark("borderWidth"); | |
77 cp = xrm_lookup(instquarks, classquarks); | |
78 if (cp) { | |
79 i = atoi(cp); | |
80 free(cp); | |
81 } else | |
82 i = 2; | |
83 /* go for it! */ | |
84 mainwindow = XCreateWindow(mydisplay, DefaultRootWindow(mydisplay), | |
85 xpos, ypos, pixwidth, pixheight, i, CopyFromParent, | |
86 InputOutput, CopyFromParent, xswamask, &xswa); | |
87 /* set window manager properties */ | |
88 xclasshint.res_name = proginstancename; | |
89 xclasshint.res_class = "LEDemu"; | |
90 XSetClassHint(mydisplay, mainwindow, &xclasshint); | |
91 wmhints.flags = InputHint | StateHint; | |
92 wmhints.input = False; | |
93 classquarks[1] = instquarks[1] = XrmStringToQuark("iconic"); | |
94 cp = xrm_lookup(instquarks, classquarks); | |
95 if (cp) { | |
96 i = parse_boolean_resource(cp); | |
97 free(cp); | |
98 } else | |
99 i = 0; | |
100 wmhints.initial_state = i ? IconicState : NormalState; | |
101 XSetWMHints(mydisplay, mainwindow, &wmhints); | |
102 if (geomask & (WidthValue|HeightValue)) | |
103 wm_normal_hints.flags = USSize; | |
104 else | |
105 wm_normal_hints.flags = PSize; | |
106 if (geomask & (XValue|YValue)) | |
107 wm_normal_hints.flags |= USPosition; | |
108 XSetWMNormalHints(mydisplay, mainwindow, &wm_normal_hints); | |
109 } | |
110 | |
111 set_initial_window_title() | |
112 { | |
113 XrmQuark instquarks[3], classquarks[3]; | |
114 register char *cp; | |
115 char buf[256]; | |
116 | |
117 instquarks[0] = xrmquark_topinstance; | |
118 classquarks[0] = xrmquark_topclass; | |
119 instquarks[1] = XrmStringToQuark("title"); | |
120 classquarks[1] = XrmStringToQuark("Title"); | |
121 instquarks[2] = classquarks[2] = NULLQUARK; | |
122 cp = xrm_lookup(instquarks, classquarks); | |
123 if (cp) { | |
124 XStoreName(mydisplay, mainwindow, cp); | |
125 free(cp); | |
126 return; | |
127 } | |
128 XStoreName(mydisplay, mainwindow, "Emulated LCD"); | |
129 } | |
130 | |
131 set_initial_icon_name() | |
132 { | |
133 XrmQuark instquarks[3], classquarks[3]; | |
134 register char *cp; | |
135 | |
136 instquarks[0] = xrmquark_topinstance; | |
137 classquarks[0] = xrmquark_topclass; | |
138 instquarks[1] = XrmStringToQuark("iconName"); | |
139 classquarks[1] = XrmStringToQuark("IconName"); | |
140 instquarks[2] = classquarks[2] = NULLQUARK; | |
141 cp = xrm_lookup(instquarks, classquarks); | |
142 if (cp) { | |
143 XSetIconName(mydisplay, mainwindow, cp); | |
144 free(cp); | |
145 return; | |
146 } | |
147 XSetIconName(mydisplay, mainwindow, proginstancename); | |
148 } | |
149 | |
150 create_mainwin_gc() | |
151 { | |
152 XGCValues xgcval; | |
153 | |
154 xgcval.graphics_exposures = False; | |
155 mainwingc = XCreateGC(mydisplay, mainwindow, GCGraphicsExposures, | |
156 &xgcval); | |
157 } |