Ejemplo n.º 1
0
gpointer
x_view_create_window (gpointer    instance,
		      const char *title,
		      int         width,
		      int         height)
{
  XViewer *x = (XViewer *) instance;
  unsigned long bg;
  Window window;
  XSizeHints size_hints;

  bg = WhitePixel (x->display, x->screen);
  window = XCreateSimpleWindow (x->display, DefaultRootWindow (x->display),
				0, 0, width, height, 0,
				bg, bg);

  XSelectInput (x->display, window, ExposureMask | KeyPressMask);
  
  XMapWindow (x->display, window);
  XmbSetWMProperties (x->display, window,
		      title,
		      NULL, NULL, 0, NULL, NULL, NULL);
  
  memset ((char *)&size_hints, 0, sizeof (XSizeHints));
  size_hints.flags = PSize | PMaxSize;
  size_hints.width = width; size_hints.height = height; /* for compat only */
  size_hints.max_width = width; size_hints.max_height = height;
  
  XSetWMNormalHints (x->display, window, &size_hints);

  return (gpointer) window;
}
Ejemplo n.º 2
0
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
{
#if defined(X_HAVE_UTF8_STRING)
    Xutf8SetWMProperties(_glfw.x11.display,
                         window->x11.handle,
                         title, title,
                         NULL, 0,
                         NULL, NULL, NULL);
#else
    // This may be a slightly better fallback than using XStoreName and
    // XSetIconName, which always store their arguments using STRING
    XmbSetWMProperties(_glfw.x11.display,
                       window->x11.handle,
                       title, title,
                       NULL, 0,
                       NULL, NULL, NULL);
#endif

    if (_glfw.x11.NET_WM_NAME != None)
    {
        XChangeProperty(_glfw.x11.display,  window->x11.handle,
                        _glfw.x11.NET_WM_NAME, _glfw.x11.UTF8_STRING, 8,
                        PropModeReplace,
                        (unsigned char*) title, strlen(title));
    }

    if (_glfw.x11.NET_WM_ICON_NAME != None)
    {
        XChangeProperty(_glfw.x11.display,  window->x11.handle,
                        _glfw.x11.NET_WM_ICON_NAME, _glfw.x11.UTF8_STRING, 8,
                        PropModeReplace,
                        (unsigned char*) title, strlen(title));
    }
}
void wintitle(pdfapp_t *app, char *s)
{
#ifdef X_HAVE_UTF8_STRING
	Xutf8SetWMProperties(xdpy, xwin, s, s, nil, 0, nil, nil, nil);
#else
	XmbSetWMProperties(xdpy, xwin, s, s, nil, 0, nil, nil, nil);
#endif
}
Ejemplo n.º 4
0
void wintitle(pdfapp_t *app, char *s)
{
	XStoreName(xdpy, xwin, s);
#ifdef X_HAVE_UTF8_STRING
	Xutf8SetWMProperties(xdpy, xwin, s, s, NULL, 0, NULL, NULL, NULL);
#else
	XmbSetWMProperties(xdpy, xwin, s, s, NULL, 0, NULL, NULL, NULL);
#endif
}
Ejemplo n.º 5
0
void wintitle(pdfapp_t *app, char *s)
{
	XStoreName(xdpy, xwin, s);
#ifdef X_HAVE_UTF8_STRING
	Xutf8SetWMProperties(xdpy, xwin, s, s, NULL, 0, NULL, NULL, NULL);
#else
	XmbSetWMProperties(xdpy, xwin, s, s, NULL, 0, NULL, NULL, NULL);
#endif
	XChangeProperty(xdpy, xwin, NET_WM_NAME, XA_UTF8_STRING, 8,
			PropModeReplace, (unsigned char *)s, strlen(s));
}
Ejemplo n.º 6
0
static Window create_window(int width, int height)
{
	int attr_list[] = {
		GLX_RGBA,
		GLX_DEPTH_SIZE, 16,
		GLX_DOUBLEBUFFER,
		None
	};
	int scrnum;
	XSetWindowAttributes attr;
	unsigned long mask;
	Window root, win;
	XVisualInfo *visinfo;
	Atom wm_protocols[1];

	if ((dpy = XOpenDisplay(NULL)) == NULL)
		return 0;

	scrnum = DefaultScreen(dpy);
	root = RootWindow(dpy, scrnum);

	if ((visinfo = glXChooseVisual(dpy, scrnum, attr_list)) == NULL)
		return 0;

	attr.background_pixel = 0;
	attr.border_pixel = 0;
	attr.colormap = colormap = XCreateColormap(dpy, root,
						   visinfo->visual, AllocNone);
	attr.event_mask = StructureNotifyMask | KeyPressMask;
	mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;

	win = XCreateWindow(dpy, root, 0, 0, width, height,
			    0, visinfo->depth, InputOutput,
			    visinfo->visual, mask, &attr);
	XmbSetWMProperties(dpy, win, _("OpenGL Spectrum analyzer"),
			   _("OpenGL Spectrum analyzer"), NULL, 0, NULL, NULL,
			   NULL);
	wm_delete_window_atom = wm_protocols[0] =
		XInternAtom(dpy, "WM_DELETE_WINDOW", False);
	XSetWMProtocols(dpy, win, wm_protocols, 1);

	glxcontext = glXCreateContext(dpy, visinfo, NULL, True);

	XFree(visinfo);

	glXMakeCurrent(dpy, win, glxcontext);

	return win;
}
static void setWindowTitle(Display *disp, Window window, jlong title, jint len) {
	Atom UTF8_STRING = XInternAtom(disp, "UTF8_STRING", True);
	Atom _NET_WM_NAME = XInternAtom(disp, "_NET_WM_NAME", True);
	Atom _NET_WM_ICON_NAME = XInternAtom(disp, "_NET_WM_ICON_NAME", True);

	// ASCII fallback if XChangeProperty fails.
    XmbSetWMProperties(disp, window, (const char *)(intptr_t)title, (const char *)(intptr_t)title, NULL, 0, NULL, NULL, NULL);

	// Set the UTF-8 encoded title
	if ( _NET_WM_NAME )
		XChangeProperty(
			disp, window, _NET_WM_NAME, UTF8_STRING,
			8, PropModeReplace, (const unsigned char *)(intptr_t)title, len
		);

	if ( _NET_WM_ICON_NAME )
		XChangeProperty(
			disp, window, _NET_WM_ICON_NAME, UTF8_STRING,
			8, PropModeReplace, (const unsigned char *)(intptr_t)title, len
		);
}
Ejemplo n.º 8
0
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
{
    Atom type = XInternAtom(_glfwLibrary.X11.display, "UTF8_STRING", False);

#if defined(X_HAVE_UTF8_STRING)
    Xutf8SetWMProperties(_glfwLibrary.X11.display,
			 window->X11.handle,
			 title, title,
			 NULL, 0,
			 NULL, NULL, NULL);
#else
    // This may be a slightly better fallback than using XStoreName and
    // XSetIconName, which always store their arguments using STRING
    XmbSetWMProperties(_glfwLibrary.X11.display,
		       window->X11.handle,
		       title, title,
		       NULL, 0,
		       NULL, NULL, NULL);
#endif

    if (_glfwLibrary.X11.wmName != None)
    {
	XChangeProperty(_glfwLibrary.X11.display,  window->X11.handle,
			_glfwLibrary.X11.wmName, type, 8,
			PropModeReplace,
			(unsigned char*) title, strlen(title));
    }

    if (_glfwLibrary.X11.wmIconName != None)
    {
	XChangeProperty(_glfwLibrary.X11.display,  window->X11.handle,
			_glfwLibrary.X11.wmIconName, type, 8,
			PropModeReplace,
			(unsigned char*) title, strlen(title));
    }
}
Ejemplo n.º 9
0
void wsCreateWindow(wsTWindow *win, int X, int Y, int wX, int hY, int bW, int cV, unsigned char D, char *label)
{
    int depth;

    win->Property = D;

    if (D & wsShowFrame)
        win->Decorations = 1;

    wsHGC = DefaultGC(wsDisplay, wsScreen);

// The window position and size.
    switch (X) {
    case -1:
        win->X = (wsMaxX / 2) - (wX / 2) + wsOrgX;
        break;

    case -2:
        win->X = wsMaxX - wX - 1 + wsOrgX;
        break;

    default:
        win->X = X;
        break;
    }

    switch (Y) {
    case -1:
        win->Y = (wsMaxY / 2) - (hY / 2) + wsOrgY;
        break;

    case -2:
        win->Y = wsMaxY - hY - 1 + wsOrgY;
        break;

    default:
        win->Y = Y;
        break;
    }

    win->Width     = wX;
    win->Height    = hY;
    win->OldX      = win->X;
    win->OldY      = win->Y;
    win->OldWidth  = win->Width;
    win->OldHeight = win->Height;

// Border size for window.
    win->BorderWidth = bW;
// Hide Mouse Cursor
    win->wsCursor = None;
    win->wsMouseEventType = cV;
    win->wsCursorData[0]  = 0;
    win->wsCursorPixmap   = XCreateBitmapFromData(wsDisplay, wsRootWin, win->wsCursorData, 1, 1);

    if (!(cV & wsShowMouseCursor))
        win->wsCursor = XCreatePixmapCursor(wsDisplay, win->wsCursorPixmap, win->wsCursorPixmap, &win->wsColor, &win->wsColor, 0, 0);

    depth = vo_find_depth_from_visuals(wsDisplay, wsScreen, NULL);

    if (depth < 15) {
        mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ColorDepthTooLow);
        guiExit(EXIT_ERROR);
    }

    XMatchVisualInfo(wsDisplay, wsScreen, depth, TrueColor, &win->VisualInfo);

// ---
    win->AtomLeaderClient = XInternAtom(wsDisplay, "WM_CLIENT_LEADER", False);
    win->AtomDeleteWindow = XInternAtom(wsDisplay, "WM_DELETE_WINDOW", False);
    win->AtomTakeFocus    = XInternAtom(wsDisplay, "WM_TAKE_FOCUS", False);
    win->AtomRolle         = XInternAtom(wsDisplay, "WM_WINDOW_ROLE", False);
    win->AtomWMSizeHint    = XInternAtom(wsDisplay, "WM_SIZE_HINT", False);
    win->AtomWMNormalHint  = XInternAtom(wsDisplay, "WM_NORMAL_HINT", False);
    win->AtomProtocols     = XInternAtom(wsDisplay, "WM_PROTOCOLS", False);
    win->AtomsProtocols[0] = win->AtomDeleteWindow;
    win->AtomsProtocols[1] = win->AtomTakeFocus;
    win->AtomsProtocols[2] = win->AtomRolle;
// ---

    win->WindowAttrib.background_pixel = BlackPixel(wsDisplay, wsScreen);
    win->WindowAttrib.border_pixel     = WhitePixel(wsDisplay, wsScreen);
    win->WindowAttrib.colormap   = XCreateColormap(wsDisplay, wsRootWin, win->VisualInfo.visual, AllocNone);
    win->WindowAttrib.event_mask = StructureNotifyMask | FocusChangeMask |
                                   ExposureMask | PropertyChangeMask |
                                   EnterWindowMask | LeaveWindowMask |
                                   VisibilityChangeMask |
                                   KeyPressMask | KeyReleaseMask;

    if ((cV & wsHandleMouseButton))
        win->WindowAttrib.event_mask |= ButtonPressMask | ButtonReleaseMask;

    if ((cV & wsHandleMouseMove))
        win->WindowAttrib.event_mask |= PointerMotionMask;

    win->WindowAttrib.cursor = win->wsCursor;
    win->WindowAttrib.override_redirect = False;

    if (D & wsOverredirect)
        win->WindowAttrib.override_redirect = True;

    win->WindowMask = CWBackPixel | CWBorderPixel |
                      CWColormap | CWEventMask | CWCursor |
                      CWOverrideRedirect;

    win->WindowID = XCreateWindow(wsDisplay,
                                  (win->Parent != 0 ? win->Parent : wsRootWin),
                                  win->X, win->Y, win->Width, win->Height, win->BorderWidth,
                                  win->VisualInfo.depth,
                                  InputOutput,
                                  win->VisualInfo.visual,
                                  win->WindowMask, &win->WindowAttrib);

    wsClassHint.res_name = "MPlayer";

    wsClassHint.res_class = "MPlayer";
    XSetClassHint(wsDisplay, win->WindowID, &wsClassHint);

    win->SizeHint.flags  = PPosition | PSize | PResizeInc | PWinGravity; // | PBaseSize;
    win->SizeHint.x      = win->X;
    win->SizeHint.y      = win->Y;
    win->SizeHint.width  = win->Width;
    win->SizeHint.height = win->Height;

    if (D & wsMinSize) {
        win->SizeHint.flags     |= PMinSize;
        win->SizeHint.min_width  = win->Width;
        win->SizeHint.min_height = win->Height;
    }

    if (D & wsMaxSize) {
        win->SizeHint.flags     |= PMaxSize;
        win->SizeHint.max_width  = win->Width;
        win->SizeHint.max_height = win->Height;
    }

    win->SizeHint.height_inc  = 1;
    win->SizeHint.width_inc   = 1;
    win->SizeHint.base_width  = win->Width;
    win->SizeHint.base_height = win->Height;
    win->SizeHint.win_gravity = StaticGravity;
    XSetWMNormalHints(wsDisplay, win->WindowID, &win->SizeHint);

    win->WMHints.flags = InputHint | StateHint;
    win->WMHints.input = True;
    win->WMHints.initial_state = NormalState;
    XSetWMHints(wsDisplay, win->WindowID, &win->WMHints);

    wsWindowDecoration(win, win->Decorations);
    XStoreName(wsDisplay, win->WindowID, label);
    XmbSetWMProperties(wsDisplay, win->WindowID, label, label, NULL, 0, NULL, NULL, NULL);

    XSetWMProtocols(wsDisplay, win->WindowID, win->AtomsProtocols, 3);
    XChangeProperty(wsDisplay, win->WindowID,
                    win->AtomLeaderClient,
                    XA_WINDOW, 32, PropModeReplace,
                    (unsigned char *)&LeaderWindow, 1);

    wsTextProperty.value    = label;
    wsTextProperty.encoding = XA_STRING;
    wsTextProperty.format   = 8;
    wsTextProperty.nitems   = strlen(label);
    XSetWMIconName(wsDisplay, win->WindowID, &wsTextProperty);

    win->wGC = XCreateGC(wsDisplay, win->WindowID,
                         GCForeground | GCBackground,
                         &win->wGCV);

    win->Visible = 0;
    win->Focused = 0;
    win->Mapped  = 0;
    win->Rolled  = 0;

    if (D & wsShowWindow)
        XMapWindow(wsDisplay, win->WindowID);

    wsCreateImage(win, win->Width, win->Height);
// --- End of creating --------------------------------------------------------------------------

    {
        int i;

        for (i = 0; i < wsWLCount; i++)
            if (wsWindowList[i] == NULL)
                break;

        if (i == wsWLCount) {
            mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_TooManyOpenWindows);
            guiExit(EXIT_ERROR);
        }

        wsWindowList[i] = win;
    }

    XFlush(wsDisplay);
    XSync(wsDisplay, False);

    win->ReDraw       = NULL;
    win->ReSize       = NULL;
    win->Idle         = NULL;
    win->MouseHandler = NULL;
    win->KeyHandler   = NULL;
    mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[ws] window is created. ( %s ).\n", label);
}
Ejemplo n.º 10
0
bool emX11WindowPort::Cycle()
{
	XWindowAttributes attr;
	XSizeHints xsh;
	emString str;
	emCursor cur;
	::Window win;
	::Cursor xcur;
	emX11WindowPort * wp;
	double vrx,vry,vrw,vrh,fx,fy,fw,fh;
	int i,x,y,w,h;
	Status xs;

	if (
		FullscreenUpdateTimer &&
		IsSignaled(FullscreenUpdateTimer->GetSignal())
	) {
		Screen.GetVisibleRect(&vrx,&vry,&vrw,&vrh);
		if (
			fabs(PaneX-vrx)>0.51 || fabs(PaneY-vry)>0.51 ||
			fabs(PaneW-vrw)>0.51 || fabs(PaneH-vrh)>0.51
		) {
			PosForced=true;
			PosPending=true;
			SizeForced=true;
			SizePending=true;
			SetViewGeometry(vrx,vry,vrw,vrh,Screen.PixelTallness);
		}

		// Workaround for lots of focus problems with several window managers:
		if (Screen.GrabbingWinPort==this) {
			XMutex.Lock();
			XGetInputFocus(Disp,&win,&i);
			XMutex.Unlock();
			wp=NULL;
			for (i=Screen.WinPorts.GetCount()-1; i>=0; i--) {
				if (Screen.WinPorts[i]->Win==win) {
					wp=Screen.WinPorts[i];
					break;
				}
			}
			if (wp==this) {
				if (!Focused) {
					Focused=true;
					SetViewFocused(true);
					emWarning("emX11WindowPort: Focus workaround 1 applied.");
				}
			}
			else {
				while (wp) {
					if (wp==this) break;
					wp=wp->Owner;
				}
				if (!wp) {
					XMutex.Lock();
					xs=XGetWindowAttributes(Disp,Win,&attr);
					XMutex.Unlock();
					if (xs && attr.map_state==IsViewable) {
						XMutex.Lock();
						XSetInputFocus(Disp,Win,RevertToNone,CurrentTime);
						XMutex.Unlock();
						emWarning("emX11WindowPort: Focus workaround 2 applied.");
					}
				}
			}
		}
	}

	if (
		!PostConstructed && !PosForced && Owner &&
		(GetWindowFlags()&emWindow::WF_FULLSCREEN)==0
	) {
		Screen.GetVisibleRect(&vrx,&vry,&vrw,&vrh);
		fx=Owner->GetViewX()-Owner->BorderL;
		fy=Owner->GetViewY()-Owner->BorderT;
		fw=Owner->GetViewWidth()+Owner->BorderL+Owner->BorderR;
		fh=Owner->GetViewHeight()+Owner->BorderT+Owner->BorderB;
		fx+=fw*0.5;
		fy+=fh*0.5;
		fw=GetViewWidth()+BorderL+BorderR;
		fh=GetViewHeight()+BorderT+BorderB;
		fx-=fw*0.5+emGetDblRandom(-0.03,0.03)*vrw;
		fy-=fh*0.5+emGetDblRandom(-0.03,0.03)*vrh;
		if (fx>vrx+vrw-fw) fx=vrx+vrw-fw;
		if (fy>vry+vrh-fh) fy=vry+vrh-fh;
		if (fx<vrx) fx=vrx;
		if (fy<vry) fy=vry;
		SetViewGeometry(
			fx+BorderL,fy+BorderT,
			GetViewWidth(),GetViewHeight(),
			Screen.PixelTallness
		);
		PosPending=true;
		PosForced=true;
	}

	if (PosPending || SizePending) {
		x=((int)GetViewX())-BorderL;
		y=((int)GetViewY())-BorderT;
		w=(int)GetViewWidth();
		h=(int)GetViewHeight();
		memset(&xsh,0,sizeof(xsh));
		xsh.flags     =PMinSize;
		xsh.min_width =MinPaneW;
		xsh.min_height=MinPaneH;
		if (PosForced) {
			xsh.flags|=PPosition|USPosition;
			xsh.x=x;
			xsh.y=y;
		}
		if (SizeForced) {
			xsh.flags|=PSize|USSize;
			xsh.width=w;
			xsh.height=h;
		}
		XMutex.Lock();
		XSetWMNormalHints(Disp,Win,&xsh);
		if (PosPending && SizePending) {
			XMoveResizeWindow(Disp,Win,x,y,w,h);
		}
		else if (PosPending) {
			XMoveWindow(Disp,Win,x,y);
		}
		else {
			XResizeWindow(Disp,Win,w,h);
		}
		XMutex.Unlock();
		PosPending=false;
		SizePending=false;
	}

	if (TitlePending) {
		str=GetWindowTitle();
		if (Title!=str) {
			Title=str;
			XMutex.Lock();
			XmbSetWMProperties(Disp,Win,Title.Get(),NULL,NULL,0,NULL,NULL,NULL);
			XMutex.Unlock();
		}
		TitlePending=false;
	}

	if (IconPending) {
		SetIconProperty(GetWindowIcon());
		IconPending=false;
	}

	if (CursorPending) {
		cur=GetViewCursor();
		if (Cursor!=cur) {
			Cursor=cur;
			xcur=Screen.GetXCursor(cur);
			XMutex.Lock();
			XDefineCursor(Disp,Win,xcur);
			XMutex.Unlock();
		}
		CursorPending=false;
	}

	if (!PostConstructed) {
		PostConstruct();
		PostConstructed=true;
	}

	if (!InvalidRects.IsEmpty() && Mapped) {
		UpdatePainting();
		if (!LaunchFeedbackSent) {
			LaunchFeedbackSent=true;
			SendLaunchFeedback();
		}
	}

	return false;
}
Ejemplo n.º 11
0
void emX11WindowPort::PreConstruct()
{
	XSetWindowAttributes xswa;
	XWMHints xwmh;
	XClassHint xch;
	XSizeHints xsh;
	XGCValues xgcv;
	long eventMask,extraEventMask;
	double vrx,vry,vrw,vrh,d;
	int border;
	bool haveBorder;

	if ((GetWindowFlags()&emWindow::WF_FULLSCREEN)!=0) {
		Screen.LeaveFullscreenModes(&GetWindow());
		Screen.GetVisibleRect(&vrx,&vry,&vrw,&vrh);
		MinPaneW=1;
		MinPaneH=1;
		PaneX=(int)(vrx+0.5);
		PaneY=(int)(vry+0.5);
		PaneW=(int)(vrw+0.5);
		PaneH=(int)(vrh+0.5);
		BorderL=0;
		BorderT=0;
		BorderR=0;
		BorderB=0;
		haveBorder=false;
		Focused=true;
	}
	else if ((GetWindowFlags()&(emWindow::WF_POPUP|emWindow::WF_UNDECORATED))!=0) {
		Screen.GetVisibleRect(&vrx,&vry,&vrw,&vrh);
		MinPaneW=1;
		MinPaneH=1;
		PaneX=(int)(vrx+vrw*emGetDblRandom(0.22,0.28)+0.5);
		PaneY=(int)(vry+vrh*emGetDblRandom(0.22,0.28)+0.5);
		PaneW=(int)(vrw*0.5+0.5);
		PaneH=(int)(vrh*0.5+0.5);
		BorderL=0;
		BorderT=0;
		BorderR=0;
		BorderB=0;
		haveBorder=false;
		Focused=true;
	}
	else {
		Screen.LeaveFullscreenModes(&GetWindow());
		Screen.GetVisibleRect(&vrx,&vry,&vrw,&vrh);
		MinPaneW=32;
		MinPaneH=32;
		if (!Owner && (GetWindowFlags()&emWindow::WF_MODAL)==0) {
			d=emMin(vrw,vrh)*0.08;
			PaneX=(int)(vrx+d*emGetDblRandom(0.5,1.5)+0.5);
			PaneY=(int)(vry+d*emGetDblRandom(0.8,1.2)+0.5);
			PaneW=(int)(vrw-d*2.0+0.5);
			PaneH=(int)(vrh-d*2.0+0.5);
		}
		else {
			PaneX=(int)(vrx+vrw*emGetDblRandom(0.22,0.28)+0.5);
			PaneY=(int)(vry+vrh*emGetDblRandom(0.22,0.28)+0.5);
			PaneW=(int)(vrw*0.5+0.5);
			PaneH=(int)(vrh*0.5+0.5);
		}
		// Some window managers seem to expect that we would expect this:
		BorderL=3;
		BorderT=18;
		BorderR=3;
		BorderB=3;
		haveBorder=true;
		if ((GetWindowFlags()&emWindow::WF_MODAL)!=0) Focused=true;
		else Focused=false;
	}
	ClipX1=PaneX;
	ClipY1=PaneY;
	ClipX2=PaneX+PaneW;
	ClipY2=PaneY+PaneH;
	PosForced=false;
	PosPending=false;
	SizeForced=false;
	SizePending=false;
	InvalidRects.Set(PaneX,PaneY,PaneX+PaneW,PaneY+PaneH);
	Title.Empty();
	TitlePending=true;
	IconPending=true;
	Cursor=-1;
	CursorPending=true;
	PostConstructed=false;
	Mapped=false;
	InputStateClock=0;
	LastButtonPress=EM_KEY_NONE;
	RepeatKey=EM_KEY_NONE;
	memset(&ComposeStatus,0,sizeof(ComposeStatus));

	memset(&xsh,0,sizeof(xsh));
	xsh.flags     =PMinSize;
	xsh.min_width =MinPaneW;
	xsh.min_height=MinPaneH;

	eventMask=
		ExposureMask|ButtonPressMask|ButtonReleaseMask|PointerMotionMask|
		KeyPressMask|KeyReleaseMask|StructureNotifyMask|SubstructureNotifyMask|
		VisibilityChangeMask|FocusChangeMask
	;

	memset(&xswa,0,sizeof(xswa));
	xswa.bit_gravity=ForgetGravity;
	xswa.colormap=Screen.Colmap;
	xswa.event_mask=eventMask;

	if (haveBorder) {
		xswa.override_redirect=False;
		border=1;
	}
	else {
		xswa.override_redirect=True;
		border=0;
	}

	XMutex.Lock();
	Win=XCreateWindow(
		Disp,
		Screen.RootWin,
		PaneX-BorderL,
		PaneY-BorderT,
		PaneW,
		PaneH,
		border,
		Screen.VisuDepth,
		InputOutput,
		Screen.Visu,
		CWBitGravity|CWColormap|CWEventMask|CWOverrideRedirect,
		&xswa
	);
	XMutex.Unlock();

	Screen.WCThread->AddWindow(Win);

	if (Owner) {
		XMutex.Lock();
		XSetTransientForHint(Disp,Win,Owner->Win);
		XMutex.Unlock();
	}

	if (Screen.InputMethod) {
		XMutex.Lock();
		InputContext=XCreateIC(
			Screen.InputMethod,
			XNInputStyle,XIMPreeditNothing|XIMStatusNothing,
			XNClientWindow,Win,
			(char*)NULL
		);
		XMutex.Unlock();
		if (InputContext==NULL) {
			emFatalError("Failed to create X input context.");
		}
	}
	else {
		InputContext=NULL;
	}

	if (InputContext) {
		XMutex.Lock();
		XGetICValues(InputContext,XNFilterEvents,&extraEventMask,(char*)NULL);
		XMutex.Unlock();
		eventMask|=extraEventMask;
	}
	XMutex.Lock();
	XSelectInput(Disp,Win,eventMask);
	XMutex.Unlock();

	memset(&xwmh,0,sizeof(xwmh));
	xwmh.flags=(InputHint|StateHint);
	xwmh.input=True;
	xwmh.initial_state=NormalState;

	memset(&xch,0,sizeof(xch));
	xch.res_name =(char*)GetWMResName().Get();
	xch.res_class=(char*)"EagleMode";

	XMutex.Lock();
	XmbSetWMProperties(Disp,Win,Title.Get(),NULL,NULL,0,&xsh,&xwmh,&xch);
	XMutex.Unlock();

	XMutex.Lock();
	XChangeProperty(
		Disp,
		Win,
		Screen.WM_PROTOCOLS,
		XA_ATOM,
		32,
		PropModeReplace,
		(const unsigned char*)&Screen.WM_DELETE_WINDOW,
		1
	);
	XMutex.Unlock();

	memset(&xgcv,0,sizeof(xgcv));
	XMutex.Lock();
	Gc=XCreateGC(Disp,Win,0,&xgcv);
	XMutex.Unlock();

	SetViewFocused(Focused);
	SetViewGeometry(PaneX,PaneY,PaneW,PaneH,Screen.PixelTallness);

	WakeUp();
}
Ejemplo n.º 12
0
int main(int argc, char**argv) {
    char **missing_charset_list;
    int missing_charset_count;
    XGCValues xgcv;
    unsigned long mask;
    Display* dpy;
    int scr;
    Window w, root;
    XSetWindowAttributes set_attr;
    int i;
    XIMStyle *style;
    static char buf[128];
    KeySym keysym = 0;
    Status status;
    XWMHints wm_hints;
    XClassHint class_hints;
    XIMStyle input_style = 0;
    char **font_name_list;
    char *def_string;
    XFontStruct **font_struct_list;
    char **font_encoding_list;
    int nb_font;
    int len = 0;
    int no_xim = 0;
    char **missing_charset_list_return;
    int missing_charset_count_return;
    char *def_string_return;

    if (!setlocale(LC_ALL, ""))
        puts("locale not supported by C library, locale unchanged");

    if (!XSetLocaleModifiers(""))
        puts("X locale modifiers not supported, using default");

    dpy = XOpenDisplay(0);
    scr = DefaultScreen(dpy);
    root = RootWindow(dpy, scr);
    set_attr.event_mask = KeyPressMask|FocusChangeMask;
    set_attr.background_pixel = WhitePixel(dpy, DefaultScreen(dpy));
    set_attr.border_pixel = BlackPixel(dpy, DefaultScreen(dpy));
    w = XCreateWindow(dpy, root, 10,10,200,100,0,
                      DefaultDepth(dpy, DefaultScreen(dpy)),
                      InputOutput, DefaultVisual(dpy, DefaultScreen(dpy)),
                      CWEventMask | CWBackPixel | CWBorderPixel, &set_attr);

    class_hints.res_name = "test";
    class_hints.res_class = "Test";
    wm_hints.input = True;
    wm_hints.flags = InputHint;

    XmbSetWMProperties(dpy, w, "test", "test", NULL, 0,
                       NULL, &wm_hints, &class_hints);

    XMapWindow(dpy, w);
    xim_im = XOpenIM(dpy, NULL, "test", "Test");
    XGetIMValues(xim_im, XNQueryInputStyle, &xim_styles, NULL, NULL);
    for (i = 0, style = xim_styles->supported_styles;
            i < xim_styles->count_styles; i++, style++) {
        if (*style == (XIMStatusNone|XIMPreeditNone)) {
            printf("this is not a XIM server !!!\n");
            no_xim = 1;
        }
        printf("input style : 0x%X\n", *style);
    }
    XFree(xim_styles);

    xim_ic = XCreateIC(xim_im,
                       XNInputStyle, (XIMPreeditNothing | XIMStatusNothing),
                       XNClientWindow, w,
                       XNFocusWindow, w,
                       NULL);
    XSetICFocus(xim_ic);

    /***************************************************************
     *  I don't recommend to use a font base name list similar
     *  to the following one in a real application ;-)
     ***************************************************************/
    fontset = XCreateFontSet(dpy,
                             "-*-*-*-*-*-*-*-*-*-*-*-*-iso8858-3," /* not valid */
                             "-*-*-medium-r-*-*-*-*-*-*-*-*-iso8859-1,"
                             "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-6,"
                             "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-8,"
                             "-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific,"
                             "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-2,"
                             "-*-*-*-*-*-*-*-*-*-*-*-*-koi8-1,"
                             "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0208.1983-0,"
                             "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0212.1990-0,"
                             "-*-*-*-*-*-*-*-*-*-*-*-*-big5-0,"
                             "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0201.1976-0,"
                             "-*-unifont-*-*-*-*-*-*-*-*-*-*-iso10646-1[0x300 0x400_0x500],"
                             "-*-*-*-*-*-*-*-*-*-*-*-*-*-*",
                             &missing_charset_list_return,
                             &missing_charset_count_return,
                             &def_string_return);
    mask = (GCForeground | GCBackground);
    xgcv.foreground = BlackPixel(dpy, DefaultScreen(dpy));
    xgcv.background = WhitePixel(dpy, DefaultScreen(dpy));

    gc = XCreateGC(dpy, w, mask, &xgcv);

    /***************************************************************/
    while (1) {
        int filtered;
        static XEvent xevent;
        static XVaNestedList list1 = 0;
        int r;

        XNextEvent(dpy, &xevent);
        if (xevent.type == KeyPress) {
            XKeyEvent *e = (XKeyEvent*) &xevent;
            printf ("0x%X %d\n", e->state, e->keycode);
        }
        filtered = XFilterEvent(&xevent, w);
        if (xevent.type == FocusOut) XUnsetICFocus(xim_ic);
        if (xevent.type == FocusIn) XSetICFocus(xim_ic);

        if (xevent.type == KeyPress && !filtered) {
            len = Xutf8LookupString(xim_ic, &xevent.xkey, buf, 127, &keysym, &status);
            Xutf8DrawImageString(dpy, w, fontset, gc, x, y, buf, len);
            Xutf8DrawString(dpy, w, fontset, gc, 0, 20, jp_txt, strlen(jp_txt));
            Xutf8DrawString(dpy, w, fontset, gc, 50, 90, rtl_txt, strlen(rtl_txt));
            buf[len] = 0;
            printf("'%s' %d\n", buf, keysym);
            buf[0] = 0;
            XCloseIM(xim_im);
        }
        if (filtered) {
            printf("Dead key\n");
        }
    }
    XFreeFontSet(dpy, fontset);
    return 0;
}
Ejemplo n.º 13
0
Window mume_x11_create_window(
    Display *display, int type, Window parent,
    int x, int y, unsigned int width, unsigned int height,
    unsigned int clazz, int eventmask)
{
    int screen;
    int depth;
    Visual *visual;
    unsigned long valuemask;
    XSetWindowAttributes attributes;
    XSizeHints *size_hints;
    XWMHints *wm_hints;
    XClassHint *class_hints;
    Window window;

    screen = DefaultScreen(display);
    visual = DefaultVisual(display, screen);

    if (clazz != InputOnly) {
        depth = DefaultDepth(display, screen);
        valuemask = CWBackPixel | CWBorderPixel;
        attributes.background_pixel = WhitePixel(display, screen);
        attributes.border_pixel = BlackPixel(display, screen);

        if (MUME_BACKWIN_MENU == type) {
            assert(RootWindow(display, screen) == parent);

            valuemask |= CWSaveUnder | CWOverrideRedirect;
            attributes.save_under = True;
            attributes.override_redirect = True;
        }
    }
    else {
        depth = 0;
        valuemask = 0;
    }

    if (None == parent)
        parent = RootWindow(display, screen);

    window = XCreateWindow(
        display, parent, x, y, width, height, 0, depth,
        clazz, visual, valuemask, &attributes);

    if (clazz != InputOnly) {
        /* Setup standard properties. */
        if (!(size_hints = XAllocSizeHints()))
            mume_abort(("allocating memory failed!\n"));

        if (!(wm_hints = XAllocWMHints()))
            mume_abort(("allocating memory failed!\n"));

        if (!(class_hints = XAllocClassHint()))
            mume_abort(("allocating memory failed!\n"));

        size_hints->flags = PPosition | PSize | PMinSize;
        size_hints->min_width = 0;
        size_hints->min_height = 0;
        wm_hints->initial_state = NormalState;
        wm_hints->input = True;
        /* wm_hints->icon_pixmap = icon_pixmap; */
        wm_hints->flags = StateHint/* | IconPixmapHint*/ | InputHint;
        class_hints->res_name = "mume";
        class_hints->res_class = "mume";

        /* or use XSizeHints, XSetClassHint, XSetWMHints */
        XmbSetWMProperties(display, window, "mume", "mume",
                           NULL, 0, size_hints, wm_hints, class_hints);

        XFree(wm_hints);
        XFree(class_hints);
        XFree(size_hints);
    }

    /* Select event */
    XSelectInput(display, window, eventmask);

    return window;
}
Ejemplo n.º 14
0
int main(int argc, char**argv)
{
	char **missing_charset_list;
	int missing_charset_count;
	XGCValues xgcv;
	unsigned long mask;
	Display* dpy;
	int scr;
	Window w, root;
	XSetWindowAttributes set_attr;
	int i;
	XIMStyle *style;
        static char buf[128];
        KeySym keysym = 0;
        Status status;
	XWMHints wm_hints;
    	XClassHint class_hints;
	XIMStyle input_style = 0;
	char **font_name_list;
	char *def_string;
	XFontStruct **font_struct_list;
	char **font_encoding_list;
	int nb_font;
	int len = 0;
	int no_xim = 0;

	printf ("A -> %c \n", XUtf8Tolower('A'));
    	if (!setlocale(LC_ALL, ""))
        	puts("locale not supported by C library, locale unchanged");

    	if (!XSetLocaleModifiers(""))
        	puts("X locale modifiers not supported, using default");
	
	dpy = XOpenDisplay(0);
	if (!dpy) { puts("cannot open display.\n"); exit(-1); }
	scr = DefaultScreen(dpy);
	root = RootWindow(dpy, scr);
	set_attr.event_mask = KeyPressMask|FocusChangeMask;
	set_attr.background_pixel = WhitePixel(dpy, DefaultScreen(dpy));
	set_attr.border_pixel = BlackPixel(dpy, DefaultScreen(dpy));
	w = XCreateWindow(dpy, root, 10,10,200,100,0, 
		DefaultDepth(dpy, DefaultScreen(dpy)),
		InputOutput, DefaultVisual(dpy, DefaultScreen(dpy)),
		CWEventMask | CWBackPixel | CWBorderPixel, &set_attr);
	if (!w) { puts("cannot creat window.\n"); exit(-1); }

	class_hints.res_name = "test";
    	class_hints.res_class = "Test";
	wm_hints.input = True;
    	wm_hints.flags = InputHint;

    	XmbSetWMProperties(dpy, w, "test", "test", NULL, 0,
                       NULL, &wm_hints, &class_hints);

	XMapWindow(dpy, w);
	xim_im = XOpenIM(dpy, NULL, "test", "Test");
	if (!xim_im) { 
		puts("cannot Open Input Manager: Try default.\n"); 
		XSetLocaleModifiers("@im=");
		xim_im = XOpenIM(dpy, NULL, "test", "Test");
		if (!xim_im) { puts("Failed exiting.\n"); exit(-1); }
	}
	XGetIMValues (xim_im, XNQueryInputStyle, &xim_styles, NULL, NULL);
    	for (i = 0, style = xim_styles->supported_styles;
         	i < xim_styles->count_styles; i++, style++)
	{
		if (i == 0 && *style == (XIMStatusNone|XIMPreeditNone)) {
			printf("this is not a XIM server !!!\n");
			no_xim = 1;
		}
        	printf("input style : 0x%X\n", *style);
	}

	xim_ic = XCreateIC(xim_im,
                        XNInputStyle, 
			(XIMPreeditNothing | XIMStatusNothing),
                        XNClientWindow, w,
			XNFocusWindow, w,
                        NULL);
	if (!xim_ic) { puts("cannot create Input Context.\n"); exit(-1);}
    	XFree(xim_styles);
	XSetICFocus(xim_ic);

	/***************************************************************/
	/** I don't recommand to use a font base name list similar 
	 *  to the following one in a real application ;-) 
	 *  You should use an iso8859-1 font, plus a single font for 
	 *  your language. */
	/***************************************************************/
        fontset = XCreateUtf8FontStruct(dpy, 
		"-*-*-*-*-*-*-*-*-*-*-*-*-iso8858-3," /* not valid */
		"-*-*-medium-r-*-*-*-*-*-*-*-*-iso8859-1,"
		"-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-6,"
		"-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-8,"
		"-*-*-*-*-*-*-*-*-*-*-*-*-ksc5601.1987-0,"
		"-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific," 
		"-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-2,"
		"-*-*-*-*-*-*-*-*-*-*-*-*-koi8-1,"
		"-*-*-*-*-*-*-*-*-*-*-*-*-jisx0208.1983-0,"
		"-*-*-*-*-*-*-*-*-*-*-*-*-jisx0212.1990-0,"
		"-*-*-*-*-*-*-*-*-*-*-*-*-big5-0,"
		"-*-*-*-*-*-*-*-*-*-*-*-*-jisx0201.1976-0,"
		"-*-unifont-*-*-*-*-*-*-*-*-*-*-iso10646-1[0x300 0x400_0x500],"
		"-*-*-*-*-*-*-*-*-*-*-*-*-*-*"); 

	/* THIS PART IS NOT REQUIERED */
	nb_font = fontset->nb_font;

        while (nb_font > 0) {
                nb_font--;
		if (fontset->fonts[nb_font]) {
               		printf("encoding=\"\" fid=%d \n  %s\n", 
			//	fontset->encodings[nb_font],
                        	fontset->fonts[nb_font]->fid,
				fontset->font_name_list[nb_font]);
		}
        }
	/* END OF NOT REQUIERED PART*/

	mask = (GCForeground | GCBackground);
	xgcv.foreground = BlackPixel(dpy, DefaultScreen(dpy));
    	xgcv.background = WhitePixel(dpy, DefaultScreen(dpy));

        gc = XCreateGC(dpy, w, mask, &xgcv);
	if (!gc) { puts("cannot create Graphic Context.\n"); exit(-1);}


	/***************************************************************/
	while (1) {
		int filtered;
	 	static XEvent xevent;
		static XVaNestedList list1 = 0;
		int r;

               	XNextEvent(dpy, &xevent);
		if (xevent.type == KeyPress) {
			XKeyEvent *e = (XKeyEvent*) &xevent;
			printf ("0x%X %d\n", e->state, e->keycode);
		}
		if (xevent.type == DestroyNotify) {
			/* XIM server has crashed */
			no_xim = 1;
			XSetLocaleModifiers("@im=");
			xim_im = XOpenIM(dpy, NULL, "test", "Test");
			if (xim_im) {
			   xim_ic = XCreateIC(xim_im,
                        	XNInputStyle, (XIMPreeditNothing | 
					XIMStatusNothing),
                        	XNClientWindow, w,
				XNFocusWindow, w,
                        	NULL);
   			} else {
				xim_ic = NULL;
			}
			if (!xim_ic) {
			 	puts("Crash recovery failed. exiting.\n");
				exit(-1);
			}
		}
		if (xevent.type != DestroyNotify) {
			filtered = XFilterEvent(&xevent, 0);
		}
		if (xevent.type == FocusOut && xim_ic) XUnsetICFocus(xim_ic);
		if (xevent.type == FocusIn && xim_ic) XSetICFocus(xim_ic);

		if (xevent.type == KeyPress && !filtered) {
 			len = XUtf8LookupString(xim_ic, &xevent.xkey, 
					buf, 127, &keysym, &status);

			if (len == 1 && buf[0] == '\b') {
				x -= XUtf8TextWidth(fontset, buf, len);
				XUtf8DrawImageString(dpy, w, fontset, gc, 
					x, y, buf, len);
			} else if (len == 1 && buf[0] == '\r') {
				y += fontset->ascent + fontset->descent;
				x = 0;
				XCloseIM(xim_im);
			} else {
				XUtf8DrawImageString(dpy, w, fontset, gc, 
					x, y, buf, len);
				x += XUtf8TextWidth(fontset, buf, len);
			}


			XUtf8DrawString(dpy, w, fontset, gc, 0, 20, 
				jp_txt, strlen(jp_txt));
	
			XUtf8DrawString(dpy, w, fontset, gc, 50, 90,
				rtl_txt, strlen(rtl_txt));
			XUtf8DrawRtlString(dpy, w, fontset, gc, 
				50, 90, rtl_txt, strlen(rtl_txt));
			buf[len] = 0;
			printf("'%s' %d %x\n", buf, keysym, keysym);
			buf[0] = 0;

                }
		if (filtered) {
			printf("Dead key\n");
		}
	}
	XFreeUtf8FontStruct(dpy, fontset);
	return 0;
}
Ejemplo n.º 15
0
// ----------------------------------------------------------------------------------------------
//  wsWindowCreate: create a new window on the screen.
//   x,y   : window position
//   w,h   : window size
//   c     : mouse cursor visible
//   p     : properties - "decoration", visible titlebar, etc ...
// ----------------------------------------------------------------------------------------------
void wsWindowCreate(wsWindow *win, int x, int y, int w, int h, int p, int c, char *label)
{
    int depth;

    win->Property = p;

    win->Decoration = ((p & wsShowFrame) != 0);

    wsWindowUpdatePosition(win, x, y, w, h);

    win->Width     = w;
    win->Height    = h;
    win->OldX      = win->X;
    win->OldY      = win->Y;
    win->OldWidth  = win->Width;
    win->OldHeight = win->Height;

/* Hide Mouse Cursor */
    win->wsCursor = None;
    win->wsMouseEventType = c;
    win->wsCursorData[0]  = 0;
    win->wsCursorPixmap   = XCreateBitmapFromData(wsDisplay, wsRootWin, win->wsCursorData, 1, 1);

    if (!(c & wsShowMouseCursor))
        win->wsCursor = XCreatePixmapCursor(wsDisplay, win->wsCursorPixmap, win->wsCursorPixmap, &win->wsColor, &win->wsColor, 0, 0);

    depth = vo_find_depth_from_visuals(wsDisplay, wsScreen, NULL);

    if (depth < 15) {
        mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ColorDepthTooLow);
        mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0);
    }

    XMatchVisualInfo(wsDisplay, wsScreen, depth, TrueColor, &win->VisualInfo);

/* --- */
    win->AtomLeaderClient = XInternAtom(wsDisplay, "WM_CLIENT_LEADER", False);
    win->AtomDeleteWindow = XInternAtom(wsDisplay, "WM_DELETE_WINDOW", False);
    win->AtomTakeFocus    = XInternAtom(wsDisplay, "WM_TAKE_FOCUS", False);
    win->AtomRolle         = XInternAtom(wsDisplay, "WM_WINDOW_ROLE", False);
    win->AtomWMSizeHint    = XInternAtom(wsDisplay, "WM_SIZE_HINT", False);
    win->AtomWMNormalHint  = XInternAtom(wsDisplay, "WM_NORMAL_HINT", False);
    win->AtomProtocols     = XInternAtom(wsDisplay, "WM_PROTOCOLS", False);
    win->AtomsProtocols[0] = win->AtomDeleteWindow;
    win->AtomsProtocols[1] = win->AtomTakeFocus;
    win->AtomsProtocols[2] = win->AtomRolle;
/* --- */

    win->WindowAttrib.border_pixel = WhitePixel(wsDisplay, wsScreen);
    win->WindowAttrib.colormap     = XCreateColormap(wsDisplay, wsRootWin, win->VisualInfo.visual, AllocNone);
    win->WindowAttrib.event_mask   = StructureNotifyMask | FocusChangeMask |
                                     ExposureMask | PropertyChangeMask |
                                     EnterWindowMask | LeaveWindowMask |
                                     VisibilityChangeMask |
                                     KeyPressMask | KeyReleaseMask;

    if ((c & wsHandleMouseButton))
        win->WindowAttrib.event_mask |= ButtonPressMask | ButtonReleaseMask;

    if ((c & wsHandleMouseMove))
        win->WindowAttrib.event_mask |= PointerMotionMask;

    win->WindowAttrib.cursor = win->wsCursor;
    win->WindowAttrib.override_redirect = False;

    if (p & wsOverredirect)
        win->WindowAttrib.override_redirect = True;

    win->WindowMask = CWBorderPixel |
                      CWColormap | CWEventMask | CWCursor |
                      CWOverrideRedirect;

    win->WindowID = XCreateWindow(wsDisplay,
                                  (win->Parent != 0 ? win->Parent : wsRootWin),
                                  win->X, win->Y, win->Width, win->Height, 0,
                                  win->VisualInfo.depth,
                                  InputOutput,
                                  win->VisualInfo.visual,
                                  win->WindowMask, &win->WindowAttrib);

    wsClassHint.res_name = "MPlayer";

    wsClassHint.res_class = "MPlayer";
    XSetClassHint(wsDisplay, win->WindowID, &wsClassHint);

    wsWindowSizeHint(win);

    win->WMHints.flags = InputHint | StateHint;
    win->WMHints.input = True;
    win->WMHints.initial_state = NormalState;
    XSetWMHints(wsDisplay, win->WindowID, &win->WMHints);

    wsWindowDecoration(win);
    XStoreName(wsDisplay, win->WindowID, label);
    XmbSetWMProperties(wsDisplay, win->WindowID, label, label, NULL, 0, NULL, NULL, NULL);

    XSetWMProtocols(wsDisplay, win->WindowID, win->AtomsProtocols, 3);
    XChangeProperty(wsDisplay, win->WindowID,
                    win->AtomLeaderClient,
                    XA_WINDOW, 32, PropModeReplace,
                    (unsigned char *)&LeaderWindow, 1);

    wsTextProperty.value    = label;
    wsTextProperty.encoding = XA_STRING;
    wsTextProperty.format   = 8;
    wsTextProperty.nitems   = strlen(label);
    XSetWMIconName(wsDisplay, win->WindowID, &wsTextProperty);

    win->wGC = XCreateGC(wsDisplay, win->WindowID,
                         0,
                         NULL);

    win->Visible = wsNo;
    win->Focused = wsNo;
    win->Mapped  = wsNo;
    win->Rolled  = wsNo;

    if (p & wsShowWindow) {
        XMapWindow(wsDisplay, win->WindowID);
        wsWindowMapWait(win);
    }

    wsImageCreate(win, win->Width, win->Height);
/* End of creating -------------------------------------------------------------------------- */

    {
        int i;

        for (i = 0; i < wsWLCount; i++)
            if (wsWindowList[i] == NULL)
                break;

        if (i == wsWLCount) {
            mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_TooManyOpenWindows);
            mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0);
        }

        wsWindowList[i] = win;
    }

    XFlush(wsDisplay);
    XSync(wsDisplay, False);

    win->DrawHandler  = NULL;
    win->MouseHandler = NULL;
    win->KeyHandler   = NULL;
    mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] window is created. ( %s ).\n", label);
}
Ejemplo n.º 16
0
EIF_BOOLEAN basic_gui_initialize(EIF_POINTER display_name,
				 EIF_BOOLEAN sync,
				 EIF_BOOLEAN no_xshm,
				 EIF_POINTER name,
				 EIF_POINTER progclass,
				 EIF_POINTER gxid_host,
				 EIF_INTEGER gxid_port) {
  /*
     Called only once at the very beginning to initialize the Window Manager.
  */
  int synchronize = sync;
  XKeyboardState keyboard_state;
  XClassHint *class_hint;
  X_GETTIMEOFDAY (&start);
  gdk_display_name = display_name;
  XSetErrorHandler (gui_x_error);
  XSetIOErrorHandler (gui_x_io_error);
  g_get_prgname = name;
  gdk_display_name = display_name;
  if (no_xshm) gdk_use_xshm = FALSE;
  gdk_progclass = progclass;
#ifdef XINPUT_GXI
  gdk_input_gxid_host = gxid_host;
  gdk_input_gxid_port = gxid_port;
#endif

  gdk_display = XOpenDisplay (gdk_display_name);
  if (!gdk_display)
    return FALSE;

  if (synchronize)
    XSynchronize (gdk_display, True);

  gdk_screen = DefaultScreen (gdk_display);

  gdk_root_window = RootWindow (gdk_display, gdk_screen);

  gdk_leader_window = XCreateSimpleWindow(gdk_display, gdk_root_window,
					  10, 10, 10, 10, 0, 0 , 0);
  class_hint = XAllocClassHint();
  class_hint->res_name = g_get_prgname;
  if (gdk_progclass == NULL) {
    gdk_progclass = g_get_prgname;
  }
  class_hint->res_class = gdk_progclass;
  XmbSetWMProperties (gdk_display, gdk_leader_window,
		      NULL, NULL, se_argv, se_argc,
		      NULL, NULL, class_hint);
  XFree (class_hint);
  gdk_wm_delete_window = XInternAtom (gdk_display, "WM_DELETE_WINDOW", False);
  gdk_wm_take_focus = XInternAtom (gdk_display, "WM_TAKE_FOCUS", False);
  gdk_wm_protocols = XInternAtom (gdk_display, "WM_PROTOCOLS", False);
  gdk_wm_window_protocols[0] = gdk_wm_delete_window;
  gdk_wm_window_protocols[1] = gdk_wm_take_focus;
  gdk_selection_property = XInternAtom (gdk_display, "GDK_SELECTION", False);

  XGetKeyboardControl (gdk_display, &keyboard_state);

  autorepeat = keyboard_state.global_auto_repeat;

  timer.tv_sec = 0;
  timer.tv_usec = 0;
  timerp = NULL;

  /* @@@ Keep This ?:
     gdk_events_init ();
     gdk_visual_init ();
     gdk_window_init ();
     gdk_image_init ();
     gdk_input_init ();
     gdk_dnd_init ();

#ifdef USE_XIM
  gdk_im_open ();
#endif
  */
  return 1;
}
Bool
addScreen (CompDisplay *display,
	   int	       screenNum)
{
    CompScreen   *s;
    Display	 *dpy = display->display;
    static char  data = 0;
    XColor	 black, dummy;
    Pixmap	 bitmap;
    XVisualInfo  templ;
    XVisualInfo  *visinfo;
    VisualID     visualIDs[MAX_DEPTH + 1];
    Window	 rootReturn, parentReturn;
    Window	 *children;
    unsigned int nchildren;
    int		 defaultDepth, nvisinfo, value, i;
    const char   *glxExtensions, *glExtensions;
    GLint	 stencilBits;

    s = malloc (sizeof (CompScreen));
    if (!s)
	return FALSE;

    s->windowPrivateIndices = 0;
    s->windowPrivateLen     = 0;

    if (display->screenPrivateLen)
    {
	s->privates = malloc (display->screenPrivateLen *
			      sizeof (CompPrivate));
	if (!s->privates)
	{
	    free (s);
	    return FALSE;
	}
    }
    else
	s->privates = 0;

    compScreenInitOptions (s);

    s->redrawTime = 1000 / s->opt[COMP_SCREEN_OPTION_REFRESH_RATE].value.i;

    s->display = display;

    s->damage = XCreateRegion ();
    if (!s->damage)
	return FALSE;

    s->buttonGrab  = 0;
    s->nButtonGrab = 0;
    s->keyGrab     = 0;
    s->nKeyGrab    = 0;

    s->grabs    = 0;
    s->grabSize = 0;
    s->maxGrab  = 0;

    s->pendingDestroys = 0;

    s->screenNum = screenNum;
    s->colormap  = DefaultColormap (dpy, screenNum);
    s->root	 = XRootWindow (dpy, screenNum);

    if (testMode)
    {
	XSetWindowAttributes attrib;
	XWMHints	     *wmHints;
	XSizeHints	     *normalHints;
	XClassHint	     *classHint;
	int		     glx_attrib[] = {
	    GLX_RGBA,
	    GLX_RED_SIZE, 1,
	    GLX_STENCIL_SIZE, 2,
	    GLX_DOUBLEBUFFER,
	    None
	};

	visinfo = glXChooseVisual (dpy, screenNum, glx_attrib);
	if (!visinfo)
	{
	    int glx_attrib2[] = {
		GLX_RGBA,
		GLX_RED_SIZE, 1,
		GLX_DOUBLEBUFFER,
		None
	    };

	    visinfo = glXChooseVisual (dpy, screenNum, glx_attrib2);
	    if (!visinfo)
	    {
		fprintf (stderr, "%s: Couldn't find a double buffered "
			 "RGB visual.\n", programName);
		return FALSE;
	    }
	}

	attrib.colormap = XCreateColormap (dpy, s->root, visinfo->visual,
					   AllocNone);

	normalHints = XAllocSizeHints ();
	normalHints->flags = 0;
	normalHints->x = 0;
	normalHints->y = 0;
	normalHints->width = 800;
	normalHints->height = 600;

	classHint = XAllocClassHint ();
	classHint->res_name = "glxcompmgr";
	classHint->res_class = "Glxcompmgr";

	wmHints = XAllocWMHints ();
	wmHints->flags = InputHint;
	wmHints->input = TRUE;

	s->root = XCreateWindow (dpy, s->root, 0, 0,
				 normalHints->width, normalHints->height, 0,
				 visinfo->depth, InputOutput, visinfo->visual,
				 CWColormap, &attrib);

	XSetWMProtocols (dpy, s->root, &display->wmDeleteWindowAtom, 1);

	XmbSetWMProperties (dpy, s->root,
			    "glxcompmgr - Test mode", "glxcompmgr",
			    programArgv, programArgc,
			    normalHints, wmHints, classHint);

	s->fake[0] = XCreateWindow (dpy, s->root, 64, 32, 1, 1, 0,
				    visinfo->depth, InputOutput,
				    visinfo->visual,
				    CWColormap, &attrib);

	s->fake[1] = XCreateWindow (dpy, s->root, 256, 256, 1, 1, 0,
				    visinfo->depth, InputOutput,
				    visinfo->visual,
				    CWColormap, &attrib);

	XMapWindow (dpy, s->root);

	XFree (wmHints);
	XFree (classHint);
	XFree (normalHints);
    }
    else
	s->fake[0] = s->fake[1] = 0;

    s->escapeKeyCode = XKeysymToKeycode (display->display,
					 XStringToKeysym ("Escape"));

    s->allDamaged  = TRUE;
    s->next	   = 0;
    s->exposeRects = 0;
    s->sizeExpose  = 0;
    s->nExpose     = 0;

    s->rasterX = 0;
    s->rasterY = 0;

    s->windows = 0;
    s->reverseWindows = 0;

    s->stencilRef = 0x1;

    s->nextRedraw = 0;

    gettimeofday (&s->lastRedraw, 0);

    s->setScreenOption	        = setScreenOption;
    s->setScreenOptionForPlugin = setScreenOptionForPlugin;

    s->initPluginForScreen = initPluginForScreen;
    s->finiPluginForScreen = finiPluginForScreen;

    s->preparePaintScreen     = preparePaintScreen;
    s->donePaintScreen        = donePaintScreen;
    s->paintScreen	      = paintScreen;
    s->paintTransformedScreen = paintTransformedScreen;
    s->paintBackground        = paintBackground;
    s->paintWindow            = paintWindow;
    s->addWindowGeometry      = addWindowGeometry;
    s->drawWindowGeometry     = drawWindowGeometry;
    s->invisibleWindowMove    = invisibleWindowMove;
    s->damageWindowRect       = damageWindowRect;
    s->damageWindowRegion     = damageWindowRegion;

    s->getProcAddress = 0;

    if (s->root)
    {
	XSetWindowAttributes attrib;

	attrib.override_redirect = 1;
	s->grabWindow = XCreateWindow (dpy, s->root, -100, -100, 1, 1, 0,
				       CopyFromParent, CopyFromParent,
				       CopyFromParent, CWOverrideRedirect,
				       &attrib);

	XMapWindow (dpy, s->grabWindow);
    }

    if (!XGetWindowAttributes (dpy, s->root, &s->attrib))
	return FALSE;

    s->activeWindow = None;

    templ.visualid = XVisualIDFromVisual (s->attrib.visual);

    visinfo = XGetVisualInfo (dpy, VisualIDMask, &templ, &nvisinfo);
    if (!nvisinfo)
    {
	fprintf (stderr, "%s: Couldn't get visual info for default visual\n",
		 programName);
	return FALSE;
    }

    defaultDepth = visinfo->depth;

    if (!XAllocNamedColor (dpy, s->colormap, "black", &black, &dummy))
    {
	fprintf (stderr, "%s: Couldn't allocate color\n", programName);
	return FALSE;
    }

    bitmap = XCreateBitmapFromData (dpy, s->root, &data, 1, 1);
    if (!bitmap)
    {
	fprintf (stderr, "%s: Couldn't create bitmap\n", programName);
	return FALSE;
    }

    s->invisibleCursor = XCreatePixmapCursor (dpy, bitmap, bitmap,
					      &black, &black, 0, 0);
    if (!s->invisibleCursor)
    {
	fprintf (stderr, "%s: Couldn't create invisible cursor\n",
		 programName);
	return FALSE;
    }

    XFreePixmap (dpy, bitmap);
    XFreeColors (dpy, s->colormap, &black.pixel, 1, 0);

    glXGetConfig (dpy, visinfo, GLX_USE_GL, &value);
    if (!value)
    {
	fprintf (stderr, "%s: Root visual is not a GL visual\n",
		 programName);
	return FALSE;
    }

    glXGetConfig (dpy, visinfo, GLX_DOUBLEBUFFER, &value);
    if (!value)
    {
	fprintf (stderr,
		 "%s: Root visual is not a double buffered GL visual\n",
		 programName);
	return FALSE;
    }

    s->ctx = glXCreateContext (dpy, visinfo, NULL, TRUE);
    if (!s->ctx)
    {
	fprintf (stderr, "%s: glXCreateContext failed\n", programName);
	return FALSE;
    }

    XFree (visinfo);

    /* we don't want to allocate back, stencil or depth buffers for pixmaps
       so lets see if we can find an approriate visual without these buffers */
    for (i = 0; i <= MAX_DEPTH; i++)
    {
	int j, db, stencil, depth;

	visualIDs[i] = 0;

	db	= MAXSHORT;
	stencil = MAXSHORT;
	depth	= MAXSHORT;

	templ.depth = i;

	visinfo = XGetVisualInfo (dpy, VisualDepthMask, &templ, &nvisinfo);
	for (j = 0; j < nvisinfo; j++)
	{
	    glXGetConfig (dpy, &visinfo[j], GLX_USE_GL, &value);
	    if (!value)
		continue;

	    glXGetConfig (dpy, &visinfo[j], GLX_DOUBLEBUFFER, &value);
	    if (value > db)
		continue;

	    db = value;
	    glXGetConfig (dpy, &visinfo[j], GLX_STENCIL_SIZE, &value);
	    if (value > stencil)
		continue;

	    stencil = value;
	    glXGetConfig (dpy, &visinfo[j], GLX_DEPTH_SIZE, &value);
	    if (value > depth)
		continue;

	    depth = value;
	    visualIDs[i] = visinfo[j].visualid;
	}

	if (nvisinfo)
	    XFree (visinfo);
    }

    /* create contexts for supported depths */
    for (i = 0; i <= MAX_DEPTH; i++)
    {
	templ.visualid = visualIDs[i];
	s->glxPixmapVisuals[i] = XGetVisualInfo (dpy,
						 VisualIDMask,
						 &templ,
						 &nvisinfo);
    }

    if (!s->glxPixmapVisuals[defaultDepth])
    {
	fprintf (stderr, "%s: No GL visual for default depth, "
		 "this isn't going to work.\n", programName);
	return FALSE;
    }

    glXMakeCurrent (dpy, s->root, s->ctx);
    currentRoot = s->root;

    glxExtensions = glXQueryExtensionsString (s->display->display, screenNum);
    if (!testMode && !strstr (glxExtensions, "GLX_MESA_render_texture")
        && !strstr(glxExtensions, "GLX_EXT_texture_from_drawable")
        && !strstr(glxExtensions, "GLX_EXT_texture_from_pixmap"))
    {
	fprintf (stderr, "%s: GLX_MESA_render_texture is missing\n",
		 programName);
	return FALSE;
    }

    s->getProcAddress = (GLXGetProcAddressProc)
	getProcAddress (s, "glXGetProcAddressARB");
    s->bindTexImageExt = (GLXBindTexImageExtProc)
        getProcAddress (s, "glXBindTexImageEXT");
    s->bindTexImageMesa = (GLXBindTexImageMesaProc)
	getProcAddress (s, "glXBindTexImageMESA");
    s->releaseTexImage = (GLXReleaseTexImageProc)
	getProcAddress (s, "glXReleaseTexImageEXT");
    if (!s->releaseTexImage)
        s->releaseTexImage = (GLXReleaseTexImageProc)
            getProcAddress (s, "glXReleaseTexImageMESA");
    s->queryDrawable = (GLXQueryDrawableProc)
	getProcAddress (s, "glXQueryDrawable");

    if (!testMode && !s->bindTexImageExt && !s->bindTexImageMesa)
    {
	fprintf (stderr, "%s: glXBindTexImage{EXT,MESA} are missing\n",
                 programName);
	return FALSE;
    }

    if (!testMode && !s->releaseTexImage)
    {
	fprintf (stderr, "%s: glXReleaseTexImage{EXT,MESA} are missing\n",
		 programName);
	return FALSE;
    }

    if (!testMode && !s->queryDrawable)
    {
	fprintf (stderr, "%s: glXQueryDrawable is missing\n", programName);
	return FALSE;
    }

    s->textureRectangle = 0;
    glExtensions = (const char *) glGetString (GL_EXTENSIONS);
    if (strstr (glExtensions, "GL_NV_texture_rectangle")  ||
	strstr (glExtensions, "GL_EXT_texture_rectangle") ||
	strstr (glExtensions, "GL_ARB_texture_rectangle"))
	s->textureRectangle = 1;

    s->textureNonPowerOfTwo = 0;
    if (strstr (glExtensions, "GL_ARB_texture_non_power_of_two"))
	s->textureNonPowerOfTwo = 1;

    if (!(s->textureRectangle || s->textureNonPowerOfTwo))
    {
	fprintf (stderr, "%s: Support for non power of two textures missing\n",
		 programName);
	return FALSE;
    }

    s->textureEnvCombine = 0;
    if (strstr (glExtensions, "GL_ARB_texture_env_combine"))
	s->textureEnvCombine = 1;

    s->maxTextureUnits = 1;
    if (strstr (glExtensions, "GL_ARB_multitexture"))
    {
	s->activeTexture = (GLActiveTextureProc)
	    getProcAddress (s, "glActiveTexture");
	s->clientActiveTexture = (GLClientActiveTextureProc)
	    getProcAddress (s, "glClientActiveTexture");

	if (s->activeTexture && s->clientActiveTexture)
	    glGetIntegerv (GL_MAX_TEXTURE_UNITS_ARB, &s->maxTextureUnits);
    }

    initTexture (s, &s->backgroundTexture);

    s->desktopWindowCount = 0;

    glGetIntegerv (GL_STENCIL_BITS, &stencilBits);
    if (!stencilBits)
    {
	fprintf (stderr, "%s: No stencil buffer. Clipping of transformed "
		 "windows is not going to be correct when screen is "
		 "transformed.\n", programName);
    }

    glClearColor (0.0, 0.0, 0.0, 1.0);
    glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    glEnable (GL_CULL_FACE);
    glDisable (GL_BLEND);
    glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    glColor4usv (defaultColor);
    glEnableClientState (GL_VERTEX_ARRAY);
    glEnableClientState (GL_TEXTURE_COORD_ARRAY);

    for (i = 1; i < s->maxTextureUnits; i++)
    {
	s->clientActiveTexture (GL_TEXTURE0_ARB + i);
	glEnableClientState (GL_TEXTURE_COORD_ARRAY);
    }

    if (s->maxTextureUnits > 1)
	s->clientActiveTexture (GL_TEXTURE0_ARB);

    s->activeWindow = getActiveWindow (display, s->root);

    reshape (s, s->attrib.width, s->attrib.height);

    s->next = display->screens;
    display->screens = s;

    screenInitPlugins (s);

    XSelectInput (dpy, s->root,
		  SubstructureNotifyMask |
		  StructureNotifyMask	 |
		  PropertyChangeMask	 |
		  ExposureMask		 |
		  ButtonPressMask	 |
		  ButtonReleaseMask	 |
		  ButtonMotionMask);

    XQueryTree (dpy, s->root,
		&rootReturn, &parentReturn,
		&children, &nchildren);

    for (i = 0; i < nchildren; i++)
    {
	if (children[i] == s->grabWindow)
	    continue;

	addWindow (s, children[i], i ? children[i - 1] : 0);
    }

    XFree (children);

    return TRUE;
}