#endif
#include <X11/extensions/xf86vmode.h>
+// get the Uchar type
+#include "utf8lib.h"
+#include "image.h"
+
#include "nexuiz.xpm"
#include "darkplaces.xpm"
Atom net_wm_state_atom;
Atom net_wm_state_hidden_atom;
Atom net_wm_state_fullscreen_atom;
+Atom net_wm_icon;
+Atom cardinal;
#define KEY_MASK (KeyPressMask | KeyReleaseMask)
#define MOUSE_MASK (ButtonPressMask | ButtonReleaseMask | \
static Colormap vidx11_colormap;
/*-----------------------------------------------------------------------*/
+//
+
+long keysym2ucs(KeySym keysym);
+void DP_Xutf8LookupString(XKeyEvent * ev,
+ Uchar *uch,
+ KeySym * keysym_return,
+ Status * status_return)
+{
+ int rc;
+ KeySym keysym;
+ int codepoint;
+ char buffer[64];
+ int nbytes = sizeof(buffer);
+
+ rc = XLookupString(ev, buffer, nbytes, &keysym, NULL);
+
+ if (rc > 0) {
+ codepoint = buffer[0] & 0xFF;
+ } else {
+ codepoint = keysym2ucs(keysym);
+ }
+
+ if (codepoint < 0) {
+ if (keysym == None) {
+ *status_return = XLookupNone;
+ } else {
+ *status_return = XLookupKeySym;
+ *keysym_return = keysym;
+ }
+ *uch = 0;
+ return;
+ }
+
+ *uch = codepoint;
-static int XLateKey(XKeyEvent *ev, char *ascii)
+ if (keysym != None) {
+ *keysym_return = keysym;
+ *status_return = XLookupBoth;
+ } else {
+ *status_return = XLookupChars;
+ }
+}
+static int XLateKey(XKeyEvent *ev, Uchar *ascii)
{
int key = 0;
- char buf[64];
+ //char buf[64];
KeySym keysym, shifted;
+ Status status;
keysym = XLookupKeysym (ev, 0);
- XLookupString(ev, buf, sizeof buf, &shifted, 0);
- *ascii = buf[0];
+ DP_Xutf8LookupString(ev, ascii, &shifted, &status);
switch(keysym)
{
{
XEvent event;
int key;
- char ascii;
+ Uchar unicode;
qboolean dowarp = false;
if (!vidx11_display)
{
case KeyPress:
// key pressed
- key = XLateKey (&event.xkey, &ascii);
- Key_Event(key, ascii, true);
+ key = XLateKey (&event.xkey, &unicode);
+ Key_Event(key, unicode, true);
break;
case KeyRelease:
// key released
- key = XLateKey (&event.xkey, &ascii);
- Key_Event(key, ascii, false);
+ key = XLateKey (&event.xkey, &unicode);
+ Key_Event(key, unicode, false);
break;
case MotionNotify:
qboolean VID_InitMode(viddef_mode_t *mode)
{
- int i;
+ int i, j;
int attrib[32];
XSetWindowAttributes attr;
XClassHint *clshints;
XVisualInfo *visinfo;
int MajorVersion, MinorVersion;
const char *drivername;
+ char *xpm;
+ char **idata;
+ unsigned char *data;
vid_isfullscreen = false;
vid_isnetwmfullscreen = false;
net_wm_state_atom = XInternAtom(vidx11_display, "_NET_WM_STATE", false);
net_wm_state_fullscreen_atom = XInternAtom(vidx11_display, "_NET_WM_STATE_FULLSCREEN", false);
net_wm_state_hidden_atom = XInternAtom(vidx11_display, "_NET_WM_STATE_HIDDEN", false);
+ net_wm_icon = XInternAtom(vidx11_display, "_NET_WM_ICON", false);
+ cardinal = XInternAtom(vidx11_display, "CARDINAL", false);
// make autorepeat send keypress/keypress/.../keyrelease instead of intervening keyrelease
XkbSetDetectableAutoRepeat(vidx11_display, true, NULL);
win = XCreateWindow(vidx11_display, root, 0, 0, mode->width, mode->height, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr);
+ data = loadimagepixelsbgra("darkplaces-icon", false, false, false, NULL);
+ if(data)
+ {
+ // use _NET_WM_ICON too
+ static long netwm_icon[MAX_NETWM_ICON];
+ int pos = 0;
+ int i = 1;
+
+ while(data)
+ {
+ if(pos + 2 * image_width * image_height < MAX_NETWM_ICON)
+ {
+ netwm_icon[pos++] = image_width;
+ netwm_icon[pos++] = image_height;
+ for(i = 0; i < image_height; ++i)
+ for(j = 0; j < image_width; ++j)
+ netwm_icon[pos++] = BuffLittleLong(&data[(i*image_width+j)*4]);
+ }
+ else
+ {
+ Con_Printf("Skipping NETWM icon #%d because there is no space left\n", i);
+ }
+ ++i;
+ Mem_Free(data);
+ data = loadimagepixelsbgra(va("darkplaces-icon%d", i), false, false, false, NULL);
+ }
+ XChangeProperty(vidx11_display, win, net_wm_icon, cardinal, 32, PropModeReplace, (const unsigned char *) netwm_icon, pos);
+ }
+
+ // fallthrough for old window managers
+ xpm = (char *) FS_LoadFile("darkplaces-icon.xpm", tempmempool, false, NULL);
+ idata = NULL;
+ if(xpm)
+ idata = XPM_DecodeString(xpm);
+ if(!idata)
+ idata = ENGINE_ICON;
+
wmhints = XAllocWMHints();
if(XpmCreatePixmapFromData(vidx11_display, win,
- (gamemode == GAME_NEXUIZ) ? nexuiz_xpm : darkplaces_xpm,
+ idata,
&wmhints->icon_pixmap, &wmhints->icon_mask, NULL) == XpmSuccess)
wmhints->flags |= IconPixmapHint | IconMaskHint;
+ if(xpm)
+ Mem_Free(xpm);
+
clshints = XAllocClassHint();
clshints->res_name = strdup(gamename);
clshints->res_class = strdup("DarkPlaces");
}
XmbSetWMProperties(vidx11_display, win, gamename, gamename, (char **) com_argv, com_argc, szhints, wmhints, clshints);
+ // strdup() allocates using malloc(), should be freed with free()
+ free(clshints->res_name);
+ free(clshints->res_class);
XFree(clshints);
XFree(wmhints);
XFree(szhints);
//XSync(vidx11_display, False);
ctx = qglXCreateContext(vidx11_display, visinfo, NULL, True);
+ XFree(visinfo); // glXChooseVisual man page says to use XFree to free visinfo
if (!ctx)
{
Con_Printf ("glXCreateContext failed\n");
++k;
}
}
+ // manpage of XF86VidModeGetAllModeLines says it should be freed by the caller
+ XFree(vidmodes);
return k;
}
return 0; // FIXME implement this