#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 | \
cvar_t vid_dgamouse = {CVAR_SAVE, "vid_dgamouse", "0", "make use of DGA mouse input"};
static qboolean vid_usingdgamouse = false;
#endif
-cvar_t vid_netwmfullscreen = {CVAR_SAVE, "vid_netwmfullscreen", "0", "make use _NET_WM_STATE_FULLSCREEN; turn this off if fullscreen does not work for you"};
+cvar_t vid_netwmfullscreen = {CVAR_SAVE, "vid_netwmfullscreen", "1", "make use _NET_WM_STATE_FULLSCREEN; turn this off if fullscreen does not work for you"};
qboolean vidmode_ext = false;
static Colormap vidx11_colormap;
/*-----------------------------------------------------------------------*/
+//
-static int XLateKey(XKeyEvent *ev, char *ascii)
+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;
+
+ 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:
void VID_Finish (void)
{
- vid_usevsync = vid_vsync.integer && !cls.timedemo && gl_videosyncavailable;
- if (vid_usingvsync != vid_usevsync && gl_videosyncavailable)
+ vid_usevsync = vid_vsync.integer && !cls.timedemo && qglXSwapIntervalSGI;
+ if (vid_usingvsync != vid_usevsync)
{
vid_usingvsync = vid_usevsync;
if (qglXSwapIntervalSGI (vid_usevsync))
Con_Print("glXSwapIntervalSGI didn't accept the vid_vsync change, it will take effect on next vid_restart (GLX_SGI_swap_control does not allow turning off vsync)\n");
}
- if (r_render.integer)
+ if (!vid_hidden)
{
CHECKGLERROR
if (r_speeds.integer == 2 || gl_finish.integer)
*attrib++ = None;
}
-int VID_InitMode(int fullscreen, int *width, int *height, int bpp, int refreshrate, int stereobuffer, int samples)
+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);
return false;
}
- VID_BuildGLXAttrib(attrib, bpp == 32, stereobuffer, samples);
+ VID_BuildGLXAttrib(attrib, mode->bitsperpixel == 32, mode->stereobuffer, mode->samples);
visinfo = qglXChooseVisual(vidx11_display, vidx11_screen, attrib);
if (!visinfo)
{
return false;
}
- if (fullscreen)
+ if (mode->fullscreen)
{
if(vid_netwmfullscreen.integer)
{
for (i = 0; i < num_vidmodes; i++)
{
- if (*width > vidmodes[i]->hdisplay || *height > vidmodes[i]->vdisplay)
+ if (mode->width > vidmodes[i]->hdisplay || mode->height > vidmodes[i]->vdisplay)
continue;
- x = *width - vidmodes[i]->hdisplay;
- y = *height - vidmodes[i]->vdisplay;
+ x = mode->width - vidmodes[i]->hdisplay;
+ y = mode->height - vidmodes[i]->vdisplay;
dist = (x * x) + (y * y);
if (best_fit == -1 || dist < best_dist)
{
// LordHavoc: changed from ActualWidth/ActualHeight =,
// to width/height =, so the window will take the full area of
// the mode chosen
- *width = vidmodes[best_fit]->hdisplay;
- *height = vidmodes[best_fit]->vdisplay;
+ mode->width = vidmodes[best_fit]->hdisplay;
+ mode->height = vidmodes[best_fit]->vdisplay;
// change to the mode
XF86VidModeSwitchToMode(vidx11_display, vidx11_screen, vidmodes[best_fit]);
// Move the viewport to top left
XF86VidModeSetViewPort(vidx11_display, vidx11_screen, 0, 0);
- Con_DPrintf("Using XVidMode fullscreen mode at %dx%d\n", *width, *height);
+ Con_DPrintf("Using XVidMode fullscreen mode at %dx%d\n", mode->width, mode->height);
}
free(vidmodes);
// use the full desktop resolution
vid_isfullscreen = true;
// width and height will be filled in later
- *width = DisplayWidth(vidx11_display, vidx11_screen);
- *height = DisplayHeight(vidx11_display, vidx11_screen);
- Con_DPrintf("Using X11 fullscreen mode at %dx%d\n", *width, *height);
+ mode->width = DisplayWidth(vidx11_display, vidx11_screen);
+ mode->height = DisplayHeight(vidx11_display, vidx11_screen);
+ Con_DPrintf("Using X11 fullscreen mode at %dx%d\n", mode->width, mode->height);
}
}
vidx11_colormap = attr.colormap = XCreateColormap(vidx11_display, root, visinfo->visual, AllocNone);
attr.event_mask = X_MASK;
- if (fullscreen)
+ if (mode->fullscreen)
{
if(vid_isnetwmfullscreen)
{
mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
}
- win = XCreateWindow(vidx11_display, root, 0, 0, *width, *height, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr);
+ 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");
szhints = XAllocSizeHints();
if(vid_resizable.integer == 0 && !vid_isnetwmfullscreen)
{
- szhints->min_width = szhints->max_width = *width;
- szhints->min_height = szhints->max_height = *height;
+ szhints->min_width = szhints->max_width = mode->width;
+ szhints->min_height = szhints->max_height = mode->height;
szhints->flags |= PMinSize | PMaxSize;
}
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");
gl_platform = "GLX";
gl_platformextensions = qglXQueryExtensionsString(vidx11_display, vidx11_screen);
- gl_videosyncavailable = false;
-
// COMMANDLINEOPTION: Linux GLX: -nogetprocaddress disables GLX_ARB_get_proc_address (not required, more formal method of getting extension functions)
// COMMANDLINEOPTION: BSD GLX: -nogetprocaddress disables GLX_ARB_get_proc_address (not required, more formal method of getting extension functions)
// COMMANDLINEOPTION: MacOSX GLX: -nogetprocaddress disables GLX_ARB_get_proc_address (not required, more formal method of getting extension functions)
// COMMANDLINEOPTION: Linux GLX: -novideosync disables GLX_SGI_swap_control
// COMMANDLINEOPTION: BSD GLX: -novideosync disables GLX_SGI_swap_control
// COMMANDLINEOPTION: MacOSX GLX: -novideosync disables GLX_SGI_swap_control
- gl_videosyncavailable = GL_CheckExtension("GLX_SGI_swap_control", swapcontrolfuncs, "-novideosync", false);
+ GL_CheckExtension("GLX_SGI_swap_control", swapcontrolfuncs, "-novideosync", false);
vid_usingmousegrab = false;
vid_usingmouse = false;
static qboolean sound_active = true;
// enable/disable sound on focus gain/loss
- if (!vid_hidden && (vid_activewindow || !snd_mutewhenidle.integer))
+ if ((!vid_hidden && vid_activewindow) || !snd_mutewhenidle.integer)
{
if (!sound_active)
{
modes[k].width = vidmodes[i]->hdisplay;
modes[k].height = vidmodes[i]->vdisplay;
modes[k].bpp = 8;
- modes[k].refreshrate = vidmodes[i]->dotclock / vidmodes[i]->htotal / vidmodes[i]->vtotal;
+ if(vidmodes[i]->dotclock && vidmodes[i]->htotal && vidmodes[i]->vtotal)
+ modes[k].refreshrate = vidmodes[i]->dotclock / vidmodes[i]->htotal / vidmodes[i]->vtotal;
+ else
+ modes[k].refreshrate = 60;
modes[k].pixelheight_num = 1;
modes[k].pixelheight_denom = 1; // xvidmode does not provide this
++k;
}
}
+ // manpage of XF86VidModeGetAllModeLines says it should be freed by the caller
+ XFree(vidmodes);
return k;
}
return 0; // FIXME implement this