Example #1
0
int main() {
	char *str = "My program title";

	dpy=XOpenDisplay(NULL);
	assert(dpy);
	scr=DefaultScreen(dpy);

	win=XCreateSimpleWindow(dpy, RootWindow(dpy,scr), 
			0, 0, /* coordinates */
			SCREEN_WIDTH/2, SCREEN_HEIGHT/2, /* size */
			1, /* border width */
			WhitePixel(dpy,scr), /* foreground */
			BlackPixel(dpy,scr)  /* background */
			);
	XMapWindow(dpy, win);
	XMoveWindow(dpy, win, 0, 0);

	XTextProperty title;
	XStringListToTextProperty(&str, 1, &title);
	XSetWMName(dpy, win, &title);
	XSetWMIconName(dpy, win, &title);


	XFlush(dpy);
	getchar();
	return EXIT_SUCCESS;
}
Example #2
0
static void sendhints(Window w,struct hints *h)
  {
  if(h->flg&1) XSetWMName(dsp,w,&h->window_name);
  if(h->flg&2) XSetWMIconName(dsp,w,&h->icon_name);
  if(h->flg&4) XSetCommand(dsp,w,h->argv,h->argc);
  if(h->flg&8) XSetClassHint(dsp,w,&h->class_hints);
  if(h->normal_hints.flags) XSetWMNormalHints(dsp,w,&h->normal_hints);  
  if(h->wm_hints.flags) XSetWMHints(dsp,w,&h->wm_hints);
  }
Example #3
0
bool XPlatformWindow::set_icon_name(const char* icon_name) {  
  XTextProperty iconName;
  if (XStringListToTextProperty((char**)&icon_name, 1, &iconName) == 0) {
    warning("X structure allocation for icon name failed--window won't work.");
    return false;
  }
  XSetWMIconName(_display, _xwindow, &iconName);
  return true;
}
Example #4
0
/*
 * Set the icon name of Infowin
 */
static errr Infowin_set_icon_name(cptr name)
{
	Status st;
	XTextProperty tp;
	char buf[128];
	char *bp = buf;
	my_strcpy(buf, name, sizeof(buf));
	st = XStringListToTextProperty(&bp, 1, &tp);
	if (st) XSetWMIconName(Metadpy->dpy, Infowin->win, &tp);
	return (0);
}
Example #5
0
/******************************************************************************
  ChangeWindowName - Self explanitory
    Original work from FvwmIdent:
      Copyright 1994, Robert Nation and Nobutaka Suzuki.
******************************************************************************/
void ChangeWindowName(char *str)
{
XTextProperty name;
  if (XStringListToTextProperty(&str,1,&name) == 0) {
    fprintf(stderr,"%s: cannot allocate window name.\n",Module);
    return;
  }
  XSetWMName(dpy,win,&name);
  XSetWMIconName(dpy,win,&name);
  XFree(name.value);
}
Example #6
0
/**************************************************************************
 *  Change the window name displayed in the icon.
 **************************************************************************/
void change_icon_name(char *str)
{
  XTextProperty name;
  
  if(str == NULL)return;
  if (XStringListToTextProperty(&str,1,&name) == 0) 
    {
      fprintf(stderr,"%s: cannot allocate window name",MyName);
      return;
    }
  XSetWMIconName(dpy,main_win,&name);
  XFree(name.value);
}
Example #7
0
/**************************************************************************
 *  Change the window name displayed in the title bar.
 **************************************************************************/
void change_window_name(char *str)
{
  XTextProperty name;

  if (XStringListToTextProperty(&str,1,&name) == 0)
    {
      fprintf(stderr,"FvwmBanner: cannot allocate window name");
      return;
    }
  XSetWMName(dpy,win,&name);
  XSetWMIconName(dpy,win,&name);
  XFree(name.value);
}
Example #8
0
void APIENTRY 
glutSetIconTitle(const char *title)
{
  XTextProperty textprop;

  assert(!__glutCurrentWindow->parent);
  textprop.value = (unsigned char *) title;
  textprop.encoding = XA_STRING;
  textprop.format = 8;
  textprop.nitems = strlen(title);
  XSetWMIconName(__glutDisplay,
    __glutCurrentWindow->win, &textprop);
  XFlush(__glutDisplay);
}
Example #9
0
void pxWindow::setTitle(char* title)
{
    Display* d = mDisplayRef.getDisplay();
    XTextProperty tp;
    tp.value = (unsigned char *)title;
    tp.encoding = XA_WM_NAME;
    tp.format = 8; // 8 bit chars
    tp.nitems = strlen(title);

    XSetWMName(d, win, &tp);
    XStoreName(d, win, title);
    XSetWMIconName(d, win, &tp);
    XSetIconName(d, win, title);
}
Example #10
0
/**
 * Set a window icon name.
 * @param win The window
 * @param t The icon name string
 *
 * Set a window icon name
 */
EAPI void
ecore_x_icccm_icon_name_set(Ecore_X_Window win,
                            const char *t)
{
   char *list[1];
   XTextProperty xprop;
   int ret;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   xprop.value = NULL;
#ifdef X_HAVE_UTF8_STRING
   list[0] = strdup(t);
   ret = Xutf8TextListToTextProperty(_ecore_x_disp, list, 1,
                                     XUTF8StringStyle, &xprop);
#else /* ifdef X_HAVE_UTF8_STRING */
   list[0] = strdup(t);
   ret = XmbTextListToTextProperty(_ecore_x_disp, list, 1,
                                   XStdICCTextStyle, &xprop);
#endif /* ifdef X_HAVE_UTF8_STRING */
   if (_ecore_xlib_sync) ecore_x_sync();
   if (ret >= Success)
     {
        XSetWMIconName(_ecore_x_disp, win, &xprop);
        if (_ecore_xlib_sync) ecore_x_sync();
        if (xprop.value)
          XFree(xprop.value);
     }
   else if (XStringListToTextProperty(list, 1, &xprop) >= Success)
     {
        XSetWMIconName(_ecore_x_disp, win, &xprop);
        if (_ecore_xlib_sync) ecore_x_sync();
        if (xprop.value)
          XFree(xprop.value);
     }

   free(list[0]);
}
Example #11
0
void
XSetWMProperties(Display * display, Window w, XTextProperty * window_name,
	XTextProperty * icon_name, char **argv, int argc,
	XSizeHints * normal_hints, XWMHints * wm_hints, XClassHint *class_hints)
{
	if (window_name)
		XSetWMName(display, w, window_name);
	if (icon_name)
		XSetWMIconName(display, w, icon_name);
	if (normal_hints)
		XSetWMNormalHints(display, w, normal_hints);
	if (wm_hints)
		XSetWMHints(display, w, wm_hints);
	if (class_hints)
		XSetWMClassHints(display, w, class_hints);
}
Example #12
0
/*
 * Set the current window's iconified title
 */
void fgPlatformGlutSetIconTitle( const char* title )
{
    XTextProperty text;

    text.value = (unsigned char *) title;
    text.encoding = XA_STRING;
    text.format = 8;
    text.nitems = strlen( title );

    XSetWMIconName(
        fgDisplay.pDisplay.Display,
        fgStructure.CurrentWindow->Window.Handle,
        &text
    );

    XFlush( fgDisplay.pDisplay.Display ); /* XXX Shouldn't need this */
}
Example #13
0
void GLUTAPIENTRY 
glutSetIconTitle(const char *title)
{
  XTextProperty textprop;
  const char **pvalue = (const char**) &textprop.value;  // See below for why...

  assert(!__glutCurrentWindow->parent);
  IGNORE_IN_GAME_MODE();
  *pvalue = title; /* We want to write "textprop.value = (unsigned char *) title;"
                      but gcc complains about discarding const-ness of pointer */
  assert(!strcmp((const char*)textprop.value, title));
  textprop.encoding = XA_STRING;
  textprop.format = 8;
  textprop.nitems = (unsigned long)strlen(title);
  XSetWMIconName(__glutDisplay,
    __glutCurrentWindow->win, &textprop);
  XFlush(__glutDisplay);
}
Example #14
0
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
void InitWindow(int width, int height)
{
	g_display = XOpenDisplay(NULL);
	if( g_display == NULL ) return;

	unsigned long background = WhitePixel(g_display, 0);
	unsigned long foreground = BlackPixel(g_display, 0);

	g_window = XCreateSimpleWindow(
		g_display,
		DefaultRootWindow(g_display),
		0, 0, width, height,
		0, 0, background);

	/* タイトルの設定を行う。 */

	const char* title_ptr = "EffekseerTest";
	char* titles_ptr[] = { (char*)title_ptr };

	XTextProperty title_prop;
	setlocale(LC_ALL,"");
	XmbTextListToTextProperty( g_display, titles_ptr, 1, XCompoundTextStyle, &title_prop );
	XSetWMName(g_display,g_window,&title_prop);

	XmbTextListToTextProperty(g_display, titles_ptr, 1, XCompoundTextStyle, &title_prop );
	XSetWMIconName(g_display,g_window,&title_prop);

	g_gc = XCreateGC(g_display, g_window, 0, 0);

	XSetBackground(g_display, g_gc, background);
	XSetForeground(g_display, g_gc, foreground);

	XMapRaised(g_display, g_window);

	XSelectInput( g_display, g_window, StructureNotifyMask | ButtonPressMask );
	
	g_wm_delete_window = XInternAtom( g_display, "WM_DELETE_WINDOW", False );
	XSetWMProtocols( g_display, g_window, &g_wm_delete_window, 1 );
}
Example #15
0
/*
 * Set the current window's iconified title
 */
void FGAPIENTRY glutSetIconTitle( const char* title )
{
    freeglut_assert_ready;
    freeglut_assert_window;

    if( ! fgStructure.Window->Parent )
    {
#if TARGET_HOST_UNIX_X11

        XTextProperty text;

        text.value = (unsigned char *) title;
        text.encoding = XA_STRING;
        text.format = 8;
        text.nitems = strlen( title );

        XSetWMIconName(
            fgDisplay.Display,
            fgStructure.Window->Window.Handle,
            &text
        );

        XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */

#elif TARGET_HOST_WIN32

        SetWindowText( fgStructure.Window->Window.Handle, title );

#elif TARGET_HOST_WINCE
        {
            wchar_t* wstr = wstr_from_str(title);

            SetWindowText( fgStructure.Window->Window.Handle, wstr );

            free(wstr);
        }
#endif
    }
}
Example #16
0
/*
 * Set the current window's iconified title
 */
void FGAPIENTRY glutSetIconTitle( const char* title )
{
    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetIconTitle" );
    FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetIconTitle" );

    if( ! fgStructure.CurrentWindow->Parent )
    {
#if TARGET_HOST_UNIX_X11

        XTextProperty text;

        text.value = (unsigned char *) title;
        text.encoding = XA_STRING;
        text.format = 8;
        text.nitems = strlen( title );

        XSetWMIconName(
            fgDisplay.Display,
            fgStructure.CurrentWindow->Window.Handle,
            &text
        );

        XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */

#elif TARGET_HOST_WIN32

        SetWindowTextA( fgStructure.CurrentWindow->Window.Handle, title );

#elif TARGET_HOST_WINCE
        {
            wchar_t* wstr = fghWstrFromStr(title);

            SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr );

            free(wstr);
        }
#endif
    }
}
Example #17
0
static void InitWindow()
{
	g_display = XOpenDisplay(NULL);
	if( g_display == nullptr ) return;

	auto background = WhitePixel(g_display, 0);
	auto foreground = BlackPixel(g_display, 0);

	g_window = XCreateSimpleWindow(
		g_display,
		DefaultRootWindow(g_display),
		0, 0, 640, 480,
		0, 0, background);

	/* タイトルの設定を行う。 */

	char* title_ptr = "WindowExternal";

	XTextProperty title_prop;
	setlocale(LC_ALL,"");
	XmbTextListToTextProperty( g_display, &(title_ptr), 1, XCompoundTextStyle, &title_prop );
	XSetWMName(g_display,g_window,&title_prop);

	XmbTextListToTextProperty(g_display, &(title_ptr), 1, XCompoundTextStyle, &title_prop );
	XSetWMIconName(g_display,g_window,&title_prop);

	g_gc = XCreateGC(g_display, g_window, 0, 0);

	XSetBackground(g_display, g_gc, background);
	XSetForeground(g_display, g_gc, foreground);

	XMapRaised(g_display, g_window);

	XSelectInput( g_display, g_window, StructureNotifyMask );

	g_wm_delete_window = XInternAtom( g_display, "WM_DELETE_WINDOW", False );
	XSetWMProtocols( g_display, g_window, &g_wm_delete_window, 1 );
}
Example #18
0
void xskin_start_interface( int pipe_in ) {

  int xskin_sc;
  XEvent xskin_e;
  XSetWindowAttributes xskin_attr;

  XSizeHints xskin_hint;
  XClassHint xskin_chint;
  XTextProperty ct;
  char *namlist[2];


  /* setup window */

  xskin_d     = XOpenDisplay( NULL );
  xskin_sc    = DefaultScreen( xskin_d );
  xskin_r     = RootWindow( xskin_d, xskin_sc );
  xskin_gc    = DefaultGC( xskin_d, xskin_sc );
  xskin_vis   = DefaultVisual( xskin_d, xskin_sc );
  xskin_depth = DefaultDepth( xskin_d, xskin_sc );

  xskin_w = XCreateSimpleWindow( xskin_d, xskin_r, 0, 0,
				 skin_width, skin_height, 0,
				 WhitePixel( xskin_d, xskin_sc ),
				 BlackPixel( xskin_d, xskin_sc ) );

  xskin_attr.backing_store = True;
  xskin_attr.override_redirect = False;
  XChangeWindowAttributes( xskin_d, xskin_w,
			   CWBackingStore|CWOverrideRedirect, &xskin_attr );

  XSelectInput( xskin_d, xskin_w,
		KeyPressMask|ExposureMask|
		EnterWindowMask|LeaveWindowMask|
		ButtonPressMask|ButtonReleaseMask|
		Button1MotionMask );

  xskin_hint.flags = USSize | PMinSize | PMaxSize | USPosition;
  xskin_hint.width = xskin_hint.min_width = xskin_hint.max_width
    = skin_width;
  xskin_hint.height = xskin_hint.min_height = xskin_hint.max_height
    = skin_height;
  XSetNormalHints( xskin_d, xskin_w, &xskin_hint );

  xskin_chint.res_name  = XSKIN_RES_NAME;
  xskin_chint.res_class = XSKIN_RES_CLASS;
  XSetClassHint( xskin_d, xskin_w, &xskin_chint );

  namlist[0]=(char *)safe_malloc(strlen(XSKIN_WINDOW_NAME)+1);
  strcpy( namlist[0], XSKIN_WINDOW_NAME );
  XmbTextListToTextProperty( xskin_d, namlist, 1, XCompoundTextStyle, &ct );
  XSetWMName( xskin_d, xskin_w, &ct );
  XSetWMIconName( xskin_d, xskin_w, &ct );
  free(namlist[0]);


  /* setup pixmaps */

  if ( load_skins()!=0 ) goto finish;

  XSetWindowBackgroundPixmap( xskin_d, xskin_w, xskin_back );
  XClearWindow( xskin_d, xskin_w );

  XMapWindow( xskin_d, xskin_w );
  while( 1 ) {
    XNextEvent( xskin_d, &xskin_e );
    if ( xskin_e.type == Expose ) break; 
  }

  fshuf=0;
  frep=0;
  fequ=1;
  fpll=1;
  fplay=0;
  fpause=0;
  fremain=0;
  play_val=1;
  vol_val=50;
  last_current_time=0;
  total_time=0;
  speana_buf = NULL;
  strcpy( last_text, "welcome to timidity" );

  install_sighandler();

  repaint();
  ts_spectrum( -1, speana_buf );

  XFlush(xskin_d);

  xskin_jobs( pipe_in );   /* tskin main jobs */

finish:
  signal_vector(0);  /* finish */
}
Example #19
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);
}
Example #20
0
int main() {
	XTextProperty title;
	XEvent event; 
	XSizeHints *hints;
	XWMHints *wm_hints;
	KeySym key;

	Pixmap pix;

	pthread_t thread;
	
	/* grepare toPlot function */
	spline_init();

	/* visual routines */
	int pressed_1[3] = {0, 0, 0};	// pressed state of button1: condition and coordinates

	char *caption = "Interpolation";
	char *dpy_str = getenv("DISPLAY");

	fprintf(stderr, "Connecting to %s\t ", dpy_str);
	dpy = XOpenDisplay(dpy_str);
	if( !dpy ) {
		fprintf(stderr, "Unable to connect\n");
		exit(EXIT_FAILURE);
	} else {
		fprintf(stderr, "OK\n");
	}

	scr = DefaultScreen(dpy);
	getColors();

	width = 2 * DisplayWidth(dpy, scr) / 3;
	height = 2 * DisplayHeight(dpy, scr) / 3;

	win = XCreateSimpleWindow(dpy,
			RootWindow(dpy, scr),
			0, 0,
			width, height,
			0,
			black, white
			);

	XStringListToTextProperty(&caption, 1, &title);
	XSetWMName(dpy, win, &title);
	XSetWMIconName(dpy, win, &title);


	cont = XCreateGC(dpy, win, 0, NULL);

	if( cont<0 ) {
		fprintf(stderr, "XCReateGC: unable to set GC");
		exit(EXIT_FAILURE);
	}

	/* making window unresizeable */
	hints = XAllocSizeHints();
	if( !hints ) {
		fprintf(stderr, "XAllocSizeHints: out of memory");
		exit(EXIT_FAILURE);
	}
	hints->flags = PMaxSize | PMinSize;
	hints->min_width = width;
	hints->min_height = height;
	hints->max_width = width;
	hints->max_height = height;
	XSetWMNormalHints(dpy, win, hints);
	XFree(hints);

	/* setting icon */
	pix = XCreateBitmapFromData(dpy, win, icon_bits, icon_width, icon_height);
	if( !pix ) {
		fprintf(stderr, "XCreateBitmapFromData: cannot create icon");
		exit(EXIT_FAILURE);
	}

	wm_hints = XAllocWMHints(); 
	if( !wm_hints ) {
		fprintf(stderr, "XAllocWMHints: out of memory");
		exit(EXIT_FAILURE);
	}
	wm_hints->flags = IconPixmapHint | StateHint | IconPositionHint;
	wm_hints->icon_pixmap = pix;
	wm_hints->initial_state = IconicState;
	wm_hints->icon_x = 0;
	wm_hints->icon_y = 0;

	XSetWMHints(dpy, win, wm_hints);
	XFree(wm_hints);
	

	/* making window visible */
	XMapWindow(dpy, win);
	draw(2,1);

	XSelectInput(dpy, win, ExposureMask | KeyPressMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask);

	while( 1 ) {
		XNextEvent(dpy, &event);
		switch( event.type ) {
			case Expose:
				if( event.xexpose.count>0 )
					break;
				draw(0,1);
				XFlush(dpy);
				break;
			case KeyPress:
				XLookupString((XKeyEvent*) &event, NULL, 0, &key, NULL);
				/* moving window */
				switch( key ) {
					case XK_Down:
						pthread_create(&thread, NULL, dec, (void*)&shift_y);
						break;
					case XK_Up:
						pthread_create(&thread, NULL, inc, (void*)&shift_y);
						break;
					case XK_Right:
						pthread_create(&thread, NULL, dec, (void*)&shift_x);
						break;
					case XK_Left:
						pthread_create(&thread, NULL, inc, (void*)&shift_x);
						break;
					case XK_plus:
						pthread_create(&thread, NULL, inc, (void*)&shift_pix);
						break;
					case XK_minus:
						pthread_create(&thread, NULL, dec, (void*)&shift_pix);
						break;
					case XK_equal:
						pthread_create(&thread, NULL, def, (void*)NULL);
						break;
					case XK_Escape:
						XCloseDisplay(dpy);
						exit(EXIT_SUCCESS);
					default:
						break;
				}
				break;
			case ButtonPress:
				switch( event.xbutton.button ) {
					case Button1:
						pressed_1[0]=1;
						pressed_1[1]=event.xmotion.x;
						pressed_1[2]=event.xmotion.y;
						break;
					default:
						break;
				}
				break;
			case ButtonRelease:
				switch( event.xbutton.button ) {
					case Button1:
						pressed_1[0]=0;
						break;
					default:
						break;
				}
				break;

			case MotionNotify:
				if( pressed_1[0] ) {
					/* if button_1 is pressed while moving */
					draw(1,0);
					shift_x-=pressed_1[1]-event.xmotion.x;
					shift_y-=pressed_1[2]-event.xmotion.y;
					pressed_1[1]=event.xmotion.x;
					pressed_1[2]=event.xmotion.y;
					draw(1,1);
				}
				pos_x=event.xmotion.x;
				pos_y=event.xmotion.y;
				drawInfo();

				break;
			default:
				break;
		} /* switch(event.type) */
	} /* endless loop */

	XCloseDisplay(dpy);
	return EXIT_SUCCESS;
}
Example #21
0
/*******************************************************************************\
|* openXwindow                                                                 *|
\*******************************************************************************/
void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bits, 
		 int pixmask_width, int pixmask_height, int withdrawn) {

	unsigned int	borderwidth = 0;
	XClassHint     	classHint;
	char	       	*display_name = NULL;
	XTextProperty	name;
	XGCValues      	gcv;
	unsigned long	gcm;
	Status			status;
	int				dummy=0, i;
  
	wname = PACKAGE;
	
	for (i=1; argv[i]; i++) {
		if ((!strcmp(argv[i], "-display")) || (!strcmp(argv[i], "-d")))
			display_name = argv[i+1];
	}
  
  if (!(display = XOpenDisplay(display_name))) {
    fprintf(stderr, "%s: can't open display %s\n", 
	    wname, XDisplayName(display_name));
    exit(1);
  }

  if ( !withdrawn )
	borderwidth = 5;

  screen  = DefaultScreen(display);
  Root    = RootWindow(display, screen);
  d_depth = DefaultDepth(display, screen);
  x_fd    = XConnectionNumber(display);
  
  /* Convert XPM to XImage */
  GetXPM(&wmgen, pixmap_bytes);
  
  /* Create a window to hold the stuff */
  mysizehints.flags = USSize | USPosition;
  mysizehints.x = 0;
  mysizehints.y = 0;
  
  back_pix = GetColor("white");
  fore_pix = GetColor("black");
  
  XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints,
	      &mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy);
  
  mysizehints.min_width = 
    mysizehints.max_width =
    mysizehints.width = 64;
  
  mysizehints.min_height =
    mysizehints.max_height =
    mysizehints.height = 64;
  mysizehints.flags |= PMinSize|PMaxSize;
  
  win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y,
			    mysizehints.width, mysizehints.height, borderwidth, 
			    fore_pix, back_pix);
  
  iconwin = XCreateSimpleWindow(display, win, mysizehints.x, mysizehints.y,
				mysizehints.width, mysizehints.height, borderwidth, 
				fore_pix, back_pix);
  
  /* Activate hints */
  XSetWMNormalHints(display, win, &mysizehints);
  XSetWMNormalHints(display, iconwin, &mysizehints); /* new AQ */
  classHint.res_name = wname;
  classHint.res_class = wname;
  XSetClassHint(display, win, &classHint);
  
  XSelectInput(display, win, 
	       ButtonPressMask | ExposureMask | 
	       ButtonReleaseMask | /*PointerMotionMask |*/ StructureNotifyMask);
  XSelectInput(display, iconwin, 
	       ButtonPressMask | ExposureMask | 
	       ButtonReleaseMask | /*PointerMotionMask |*/ StructureNotifyMask);


/*	if (XStringListToTextProperty(&fullname, 1, &name) == 0) { */  
	if (XStringListToTextProperty(&wname, 1, &name) == 0) {
		fprintf(stderr, "%s: can't allocate window name\n", wname);
		exit(1);
	}

	XSetWMName(display, win, &name);
	if ( !withdrawn ) {
		XSetWMIconName(display, win, &name);
		SetWindowName(wname);
	}

  /* Create GC for drawing */
  
  gcm = GCForeground | GCBackground | GCGraphicsExposures;
  gcv.foreground = fore_pix;
  gcv.background = back_pix;
  gcv.graphics_exposures = 0;
  NormalGC = XCreateGC(display, Root, gcm, &gcv);
  
  /* ONLYSHAPE ON */

  if ( withdrawn ) {
    pixmask = XCreateBitmapFromData(display, win, pixmask_bits, 
				    pixmask_width, pixmask_height);
    XShapeCombineMask(display, win, ShapeBounding, 0, 0, pixmask, ShapeSet);
    XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet);
  }
  /* ONLYSHAPE OFF */
  
  mywmhints.initial_state = withdrawn ? WithdrawnState : NormalState;
  mywmhints.icon_window = iconwin;
  mywmhints.flags = StateHint | IconWindowHint;

  if ( withdrawn ) {
    mywmhints.window_group = win;
    mywmhints.flags |= WindowGroupHint | IconPositionHint;
    mywmhints.icon_x = mysizehints.x;
    mywmhints.icon_y = mysizehints.y;
  }
  
  XSetWMHints(display, win, &mywmhints);
  XSetCommand(display, win, argv, argc);
  
  /* Set up the event for quitting the window */
  wm_delete_window = XInternAtom(display, 
				 "WM_DELETE_WINDOW",	/* atom_name */
				 False);		/* only_if_exists */

  wm_protocols = XInternAtom(display,
			     "WM_PROTOCOLS",		/* atom_name */
			     False);			/* only_if_exists */

  status = XSetWMProtocols(display, win, &wm_delete_window, 1);
  status = XSetWMProtocols(display, iconwin, &wm_delete_window,	1);

  XMapWindow(display, win);

}
Example #22
0
LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
	XSizeHints				*pSH;
	XSetWindowAttributes	xa;
	XTextProperty			WindowTitle;
	char *					WindowTitleText;
	xPriv					*priv;

	if (!initdone) {
		gfxThreadHandle			hth;

		initdone = TRUE;
		#if GFX_USE_OS_LINUX || GFX_USE_OS_OSX
			XInitThreads();
		#endif

		dis = XOpenDisplay(0);
		scr = DefaultScreen(dis);
		cxt = XUniqueContext();
		wmDelete = XInternAtom(dis, "WM_DELETE_WINDOW", False);
		XSetIOErrorHandler(FatalXIOError);

		#if GDISP_FORCE_24BIT
			if (!XMatchVisualInfo(dis, scr, 24, TrueColor, &vis)) {
				fprintf(stderr, "Your display has no TrueColor mode\n");
				XCloseDisplay(dis);
				return FALSE;
			}
			cmap = XCreateColormap(dis, RootWindow(dis, scr),
					vis.visual, AllocNone);
		#else
			vis.visual = CopyFromParent;
			vis.depth = DefaultDepth(dis, scr);
			cmap = DefaultColormap(dis, scr);
		#endif
		fprintf(stderr, "Running GFX Window in %d bit color\n", vis.depth);

		if (!(hth = gfxThreadCreate(waXThread, sizeof(waXThread), HIGH_PRIORITY, ThreadX, 0))) {
			fprintf(stderr, "Cannot start X Thread\n");
			XCloseDisplay(dis);
			exit(0);
		}
		#if GFX_USE_OS_LINUX || GFX_USE_OS_OSX
			pthread_detach(hth);
		#endif
		gfxThreadClose(hth);
	}

	g->priv = gfxAlloc(sizeof(xPriv));
	priv = (xPriv *)g->priv;
	g->board = 0;					// No board interface for this driver

	xa.colormap = cmap;
	xa.border_pixel = 0xFFFFFF;
	xa.background_pixel = 0x000000;

	priv->win = XCreateWindow(dis, RootWindow(dis, scr), 16, 16,
			GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT,
			0, vis.depth, InputOutput, vis.visual,
			CWBackPixel|CWColormap|CWBorderPixel, &xa);
	XSync(dis, TRUE);

	XSaveContext(dis, priv->win, cxt, (XPointer)g);
	XSetWMProtocols(dis, priv->win, &wmDelete, 1);

	{
		char					buf[132];
		sprintf(buf, "uGFX - %u", g->systemdisplay+1);
		WindowTitleText = buf;
		XStringListToTextProperty(&WindowTitleText, 1, &WindowTitle);
		XSetWMName(dis, priv->win, &WindowTitle);
		XSetWMIconName(dis, priv->win, &WindowTitle);
		XSync(dis, TRUE);
	}

	pSH = XAllocSizeHints();
	pSH->flags = PSize | PMinSize | PMaxSize;
	pSH->min_width = pSH->max_width = pSH->base_width = GDISP_SCREEN_WIDTH;
	pSH->min_height = pSH->max_height = pSH->base_height = GDISP_SCREEN_HEIGHT;
	XSetWMNormalHints(dis, priv->win, pSH);
	XFree(pSH);
	XSync(dis, TRUE);

	priv->pix = XCreatePixmap(dis, priv->win,
				GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT, vis.depth);
	XSync(dis, TRUE);

	priv->gc = XCreateGC(dis, priv->win, 0, 0);
	XSetBackground(dis, priv->gc, BlackPixel(dis, scr));
	XSync(dis, TRUE);

	// Create the associated mouse before the map
	#if GINPUT_NEED_MOUSE
		priv->mouse = (GMouse *)gdriverRegister((const GDriverVMT const *)GMOUSE_DRIVER_VMT, g);
	#endif

	XSelectInput(dis, priv->win, StructureNotifyMask);
	XMapWindow(dis, priv->win);

	// Wait for the window creation to complete (for safety)
	while(!(((volatile GDisplay *)g)->flags & GDISP_FLG_READY))
		gfxSleepMilliseconds(100);

	/* Initialise the GDISP structure to match */
    g->g.Orientation = GDISP_ROTATE_0;
    g->g.Powermode = powerOn;
    g->g.Backlight = 100;
    g->g.Contrast = 50;
    g->g.Width = GDISP_SCREEN_WIDTH;
    g->g.Height = GDISP_SCREEN_HEIGHT;

    return TRUE;
}
Example #23
0
File: edit.c Project: jff/mathspad
static int set_name(void *data, Char *pathname)
{
    EDITINFO *einf = (EDITINFO *) data;
    XTextProperty prop_name;
    Char *name;
    int namesize;
    Char *stripname, *nname;

    if (pathname == NULL) {
	EDITINFO *tinf;
	FlexArray istck;
	int i=0,j;
	int_init(istck);
	while (aig(tinf=(EDITINFO*)next_data_with_type(MAINEDITWINDOW, &i))) {
	  if (!Ustrncmp(translate(EMPTYFILE),tinf->filename, Ustrlen(translate(EMPTYFILE)))) {
	    j = Ustrtol(tinf->filename+Ustrlen(translate(EMPTYFILE)), NULL, 10);
	    int_add(istck, j);
	  }
	  i++;
	}
	i=1;
	while (int_contains(istck,i)) i++;
	int_clear(istck);
	nname = (Char *) malloc(sizeof(Char)*(Ustrlen(userdir) +
					      Ustrlen(translate("/" EMPTYFILE))
					      + 5 +Ustrlen(translate(EXTENSION))));
	concat_in(nname, userdir, translate("/" EMPTYFILE));
	stripname = nname + Ustrlen(nname);
	{ Char sb[40];
	  Char *s;
	  sb[39]=0;
	  s=Ultostr(i,sb+39);
	  Ustrcat(stripname,s);
	}
	Ustrcat(stripname, translate(EXTENSION));
    } else
        nname = pathname;
    stripname = concat(strip_name(nname),NULL);
    if (!Ustrcmp(stripname+Ustrlen(stripname)-Ustrlen(translate(EXTENSION)),
		 translate(EXTENSION)))
	stripname[Ustrlen(stripname)-Ustrlen(translate(EXTENSION))] = 0;
    namesize = Ustrlen(translate(EDITNAME)) + Ustrlen(stripname) + 1 +
	(einf->saved ? 0 : Ustrlen(translate(CHANGED))) +
	(einf->view_mode && !einf->shell ? Ustrlen(translate(VIEWCOM)) : 0) +
	(einf->shell && !einf->fini ? Ustrlen(translate(RUNCOM)) : 0) +
	(einf->shell && einf->fini ? Ustrlen(translate(DONECOM)) : 0);
    name = (Char *) malloc((size_t) namesize*sizeof(Char) );
    if (name) {
	name[0]= '\0';
	Ustrcat(name, translate(EDITNAME));
	Ustrcat(name, stripname);
	if (!einf->saved && !einf->shell) Ustrcat(name, translate(CHANGED));
	if (einf->view_mode && !einf->shell) Ustrcat(name, translate(VIEWCOM));
	if (einf->shell && !einf->fini) Ustrcat(name, translate(RUNCOM));
	if (einf->shell && einf->fini) Ustrcat(name, translate(DONECOM));
    }
    {
      char *n;
      n= (char*)UstrtoLocale(name);
      if (!name || !XStringListToTextProperty(&n, 1, &prop_name)) {
	message(MP_ERROR, translate("No location for editname."));
	return 0;
      }
    }
    XSetWMName(display, einf->win_id, &prop_name);
    free(einf->headername);
    if (einf->pathname!=nname) free(einf->pathname);
    free(einf->filename);
    einf->headername = name;
    einf->filename = stripname;
    einf->pathname = nname;
    {
      char *icn;
      icn = (char*)UstrtoLocale(stripname);
      if (!XStringListToTextProperty(&icn, 1, &prop_name)) {
	message(MP_ERROR, translate("No location for editicon."));
	return 0;
      }
    }
    XSetWMIconName(display, einf->win_id, &prop_name);
    return 1;
}
Example #24
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);
}