FreeCalypso > hg > freecalypso-sw
diff lcdemu/window.c @ 903:312778104f54
lcdemu started, compiles and runs w/o actual functionality
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 07 Sep 2015 08:34:37 +0000 |
parents | |
children | e54abee27e8f |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lcdemu/window.c Mon Sep 07 08:34:37 2015 +0000 @@ -0,0 +1,172 @@ +/* + * LCDemu based on HECterm by the same author + * X11 window creation functions + */ + +#include <stdio.h> +#include <stdlib.h> +#include <X11/Xlib.h> +#include <X11/Xresource.h> +#include <X11/Xutil.h> +#include "globals.h" + +extern char *xrm_lookup(); + +create_our_window() +{ + XrmQuark instquarks[3], classquarks[3]; + register char *cp; + register int i, geomask; + int pixwidth, pixheight, xpos, ypos; + XSetWindowAttributes xswa; + u_long xswamask; + XColor bdcolor; + XClassHint xclasshint; + XWMHints wmhints; + + /* Determine our geometry */ + instquarks[0] = xrmquark_topinstance; + classquarks[0] = xrmquark_topclass; + classquarks[1] = instquarks[1] = XrmStringToQuark("geometry"); + instquarks[2] = classquarks[2] = NULLQUARK; + cp = xrm_lookup(instquarks, classquarks); + if (cp) { + geomask = XParseGeometry(cp, &xpos, &ypos, &pixwidth, + &pixheight); + free(cp); + } else + geomask = 0; + if (!(geomask & WidthValue)) + pixwidth = 176; + if (!(geomask & HeightValue)) + pixheight = 220; + if (!(geomask & XValue)) + xpos = 0; + else if (geomask & XNegative) + xpos += DisplayWidth(mydisplay, DefaultScreen(mydisplay)) - + pixwidth; + if (!(geomask & YValue)) + ypos = 0; + else if (geomask & YNegative) + ypos += DisplayHeight(mydisplay, DefaultScreen(mydisplay)) - + pixheight; + /* fill out XSetWindowAttributes */ + xswa.event_mask = 0; /* not interested in any events */ + xswamask = CWEventMask; + /* border color */ + classquarks[1] = instquarks[1] = XrmStringToQuark("borderColor"); + cp = xrm_lookup(instquarks, classquarks); + if (cp) { + i = XParseColor(mydisplay, DefaultColormap(mydisplay, + DefaultScreen(mydisplay)), cp, &bdcolor); + free(cp); + if (i) { + i = XAllocColor(mydisplay, DefaultColormap(mydisplay, + DefaultScreen(mydisplay)), &bdcolor); + if (i) { + xswa.border_pixel = bdcolor.pixel; + xswamask |= CWBorderPixel; + } + } + } + /* border width */ + classquarks[1] = instquarks[1] = XrmStringToQuark("borderWidth"); + cp = xrm_lookup(instquarks, classquarks); + if (cp) { + i = atoi(cp); + free(cp); + } else + i = 2; + /* go for it! */ + mainwindow = XCreateWindow(mydisplay, DefaultRootWindow(mydisplay), + xpos, ypos, pixwidth, pixheight, i, CopyFromParent, + InputOutput, CopyFromParent, xswamask, &xswa); + /* set window manager properties */ + xclasshint.res_name = proginstancename; + xclasshint.res_class = "LEDemu"; + XSetClassHint(mydisplay, mainwindow, &xclasshint); + wmhints.flags = InputHint | StateHint; + wmhints.input = False; + classquarks[1] = instquarks[1] = XrmStringToQuark("iconic"); + cp = xrm_lookup(instquarks, classquarks); + if (cp) { + i = parse_boolean_resource(cp); + free(cp); + } else + i = 0; + wmhints.initial_state = i ? IconicState : NormalState; + XSetWMHints(mydisplay, mainwindow, &wmhints); +#if 0 + if (geomask & (WidthValue|HeightValue)) + wm_normal_hints.flags = USSize; + else + wm_normal_hints.flags = PSize; + if (geomask & (XValue|YValue)) + wm_normal_hints.flags |= USPosition; + set_wm_normal_hints(); +#endif +} + +#if 0 +set_wm_normal_hints() +{ + wm_normal_hints.min_width = MIN_COLUMNS * charcell_width; + wm_normal_hints.min_height = MIN_LINES * charcell_height; + wm_normal_hints.max_width = MAX_COLUMNS * charcell_width; + wm_normal_hints.max_height = MAX_LINES * charcell_height; + wm_normal_hints.width_inc = charcell_width; + wm_normal_hints.height_inc = charcell_height; + wm_normal_hints.base_width = 0; + wm_normal_hints.base_height = 0; + wm_normal_hints.flags |= PMinSize | PMaxSize | PResizeInc | PBaseSize; + XSetWMNormalHints(mydisplay, mainwindow, &wm_normal_hints); +} +#endif + +set_initial_window_title() +{ + XrmQuark instquarks[3], classquarks[3]; + register char *cp; + char buf[256]; + + instquarks[0] = xrmquark_topinstance; + classquarks[0] = xrmquark_topclass; + instquarks[1] = XrmStringToQuark("title"); + classquarks[1] = XrmStringToQuark("Title"); + instquarks[2] = classquarks[2] = NULLQUARK; + cp = xrm_lookup(instquarks, classquarks); + if (cp) { + XStoreName(mydisplay, mainwindow, cp); + free(cp); + return; + } + XStoreName(mydisplay, mainwindow, "Emulated LCD"); +} + +set_initial_icon_name() +{ + XrmQuark instquarks[3], classquarks[3]; + register char *cp; + + instquarks[0] = xrmquark_topinstance; + classquarks[0] = xrmquark_topclass; + instquarks[1] = XrmStringToQuark("iconName"); + classquarks[1] = XrmStringToQuark("IconName"); + instquarks[2] = classquarks[2] = NULLQUARK; + cp = xrm_lookup(instquarks, classquarks); + if (cp) { + XSetIconName(mydisplay, mainwindow, cp); + free(cp); + return; + } + XSetIconName(mydisplay, mainwindow, proginstancename); +} + +create_mainwin_gc() +{ + XGCValues xgcval; + + xgcval.graphics_exposures = False; + mainwingc = XCreateGC(mydisplay, mainwindow, GCGraphicsExposures, + &xgcval); +}