Example #1
0
static Cursor
X11_CreateEmptyCursor()
{
    if (x11_empty_cursor == None) {
        Display *display = GetDisplay();
        char data[1];
        XColor color;
        Pixmap pixmap;

        SDL_zero(data);
        color.red = color.green = color.blue = 0;
        pixmap = XCreateBitmapFromData(display, DefaultRootWindow(display),
                                       data, 1, 1);
        if (pixmap) {
            x11_empty_cursor = XCreatePixmapCursor(display, pixmap, pixmap,
                                                   &color, &color, 0, 0);
            XFreePixmap(display, pixmap);
        }
    }
    return x11_empty_cursor;
}
Example #2
0
/***********************************************************************
 *           BRUSH_DitherMono
 */
static Pixmap BRUSH_DitherMono( COLORREF color )
{
    /* This makes the spray work in Win 3.11 pbrush.exe */
    /* FIXME. Extend this basic selection of dither patterns */
    static const char gray_dither[][2] = {{ 0x1, 0x0 }, /* DKGRAY */
                                          { 0x2, 0x1 }, /* GRAY */
                                          { 0x1, 0x3 }, /* LTGRAY */
    };                                      
    int gray = (30 * GetRValue(color) + 59 * GetGValue(color) + 11 * GetBValue(color)) / 100;
    int idx = gray * (sizeof gray_dither/sizeof gray_dither[0] + 1)/256 - 1;
    Pixmap pixmap;

    TRACE("color=%06x -> gray=%x\n", color, gray);

    wine_tsx11_lock();
    pixmap = XCreateBitmapFromData( gdi_display, root_window, 
                                    gray_dither[idx],
                                    2, 2 );
    wine_tsx11_unlock();
    return pixmap;
}
Example #3
0
/*
 * A factory method for an empty cursor
 */
static Cursor getEmptyCursor( void )
{
    static Cursor cursorNone = None;
    if( cursorNone == None ) {
        char cursorNoneBits[ 32 ];
        XColor dontCare;
        Pixmap cursorNonePixmap;
        memset( cursorNoneBits, 0, sizeof( cursorNoneBits ) );
        memset( &dontCare, 0, sizeof( dontCare ) );
        cursorNonePixmap = XCreateBitmapFromData ( fgDisplay.Display,
                                                   fgDisplay.RootWindow,
                                                   cursorNoneBits, 16, 16 );
        if( cursorNonePixmap != None ) {
            cursorNone = XCreatePixmapCursor( fgDisplay.Display,
                                              cursorNonePixmap, cursorNonePixmap,
                                              &dontCare, &dontCare, 0, 0 );
            XFreePixmap( fgDisplay.Display, cursorNonePixmap );
        }
    }
    return cursorNone;
}
X11CursorController::X11CursorController( PlatformWindow *owner ) :  PlatformCursorController( owner )
{
    AssertFatal(dynamic_cast<X11Window*>(mOwner), "X11CursorController::X11CursorController window owner not X11Window.");

    if(x86UNIXState->isXWindowsRunning())
    {
        Display* display = x86UNIXState->getDisplayPointer();

        // Setup a blank cursor so we can hide the cursor
        static char data[1] = {0};
        Cursor cursor;
        XColor dummy;
        dummy.red = dummy.green = dummy.blue = 0;
        Pixmap blank = XCreateBitmapFromData(display, DefaultRootWindow(display), data, 1, 1);
        mBlankCursor = XCreatePixmapCursor(display, blank, blank, &dummy, &dummy, 0, 0);
        XFreePixmap(display, blank);

        pushCursor( PlatformCursorController::curArrow );

    }
    mVisible = true;
};
Example #5
0
static void x11_hide_mouse(Display *dpy, Window win)
{
   static char bm_no_data[] = {0, 0, 0, 0, 0, 0, 0, 0};

   Cursor no_ptr;
   Pixmap bm_no;
   XColor black, dummy;
   Colormap colormap = DefaultColormap(dpy, DefaultScreen(dpy));
   if (!XAllocNamedColor(dpy, colormap, "black", &black, &dummy))
      return;

   bm_no  = XCreateBitmapFromData(dpy, win, bm_no_data, 8, 8);
   no_ptr = XCreatePixmapCursor(dpy, bm_no, bm_no, &black, &black, 0, 0);

   XDefineCursor(dpy, win, no_ptr);
   XFreeCursor(dpy, no_ptr);

   if (bm_no != None)
      XFreePixmap(dpy, bm_no);

   XFreeColors(dpy, colormap, &black.pixel, 1, 0);
}
Example #6
0
File: mouse.c Project: dvdhoo/wine
/***********************************************************************
 *		get_empty_cursor
 */
static Cursor get_empty_cursor(void)
{
    static Cursor cursor;
    static const char data[] = { 0 };

    wine_tsx11_lock();
    if (!cursor)
    {
        XColor bg;
        Pixmap pixmap;

        bg.red = bg.green = bg.blue = 0x0000;
        pixmap = XCreateBitmapFromData( gdi_display, root_window, data, 1, 1 );
        if (pixmap)
        {
            cursor = XCreatePixmapCursor( gdi_display, pixmap, pixmap, &bg, &bg, 0, 0 );
            XFreePixmap( gdi_display, pixmap );
        }
    }
    wine_tsx11_unlock();
    return cursor;
}
Example #7
0
static xcb_cursor_t
create_empty_cursor(struct xcb_rutabaga *self)
{
    xcb_cursor_t cursor;
    Pixmap pixmap;
    XColor color;
    char data;

    data = 0;
    color.red = color.green = color.blue = 0;

    pixmap = XCreateBitmapFromData(self->dpy,
                                   DefaultRootWindow(self->dpy), &data, 1, 1);

    if (!pixmap)
        return 0;

    cursor = XCreatePixmapCursor(self->dpy, pixmap, pixmap, &color, &color, 0, 0);
    XFreePixmap(self->dpy, pixmap);

    return cursor;
}
Example #8
0
Pixmap XbrGfxReadBitmap(Display *display, Screen *screen, GC gc, char *bits,
                        int width, int height)
{
    Pixmap bitmap, pixmap;

    /* Create a bitmap from the bits passed in */
    bitmap = XCreateBitmapFromData(display, RootWindowOfScreen(screen), bits,
      width, height);

    /* Create a pixmap with the same dimensions */
    pixmap = XCreatePixmap(display, RootWindowOfScreen(screen), width, height,
      DefaultDepthOfScreen(screen));

    /* Copy the bitmap onto the first plane of the pixmap */
    XCopyPlane(display, bitmap, pixmap, gc, 0, 0, width, height, 0, 0, 1);

    /* Finished with the bitmap */
    XFreePixmap(display, bitmap);

    /* Done. */
    return(pixmap);
}
Example #9
0
/* will initialize the library:
   open a display, initialize the rest of the UDEDesktop structure and return
   a status value as well as the desktop structure.
   return values: UDE_SUCCESS  - success.
                  UDE_FAIL     - fatal error: couldn't initialize libUDE
                  UDE_BADVAL   - success, but couldn't find uwm or uds running,
                                 using default values. */
char ude_initialize (UDEDesktop *desktop)
{
  XSetErrorHandler ((XErrorHandler)ude_error_handler);
  desktop->disp= XOpenDisplay (NULL);
  if(!desktop->disp)
    return UDE_FAIL;
  XSelectInput(desktop->disp,
               RootWindow(desktop->disp,DefaultScreen(desktop->disp)),
               PropertyChangeMask);
  UDEContext= XInternAtom (desktop->disp, "_UDE_UDEContext", False);

  ude_init_settings(desktop->disp);

#ifdef HAVE_XSHAPEQUERYEXTENSION
  XShapeQueryExtension(desktop->disp, &desktop->shape_ext.event_base,
                       &desktop->shape_ext.error_base);
#else
  desktop->shape_ext.event_base = -1;
  desktop->shape_ext.error_base = -1;
#endif

  desktop->ActualColors = NULL;
  desktop->ActiveWorkSpace = -1;
  desktop->WorkSpaces = -1;
  desktop->internal.sgrabstat = 0;
  desktop->internal.pgrabstat = NULL;
  ude_update_UDEDesktop(desktop);

  desktop->internal.raster_pixmap = XCreateBitmapFromData( desktop->disp, 
               RootWindow(desktop->disp,DefaultScreen(desktop->disp)),
               _UDE_raster_bits, _UDE_raster_width, _UDE_raster_height );
  if(None == desktop->internal.raster_pixmap) {
    ude_clean_up(desktop->disp);
    return UDE_FAIL;
  }

  return UDE_SUCCESS;
}
Example #10
0
	void Init() override
	{
		XInitThreads();
		dpy = XOpenDisplay(nullptr);

		win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy),
					  SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowXPos,
					  SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowYPos,
					  SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowWidth,
					  SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowHeight,
					  0, 0, BlackPixel(dpy, 0));
		XSelectInput(dpy, win, KeyPressMask | FocusChangeMask);
		Atom wmProtocols[1];
		wmProtocols[0] = XInternAtom(dpy, "WM_DELETE_WINDOW", True);
		XSetWMProtocols(dpy, win, wmProtocols, 1);
		XMapRaised(dpy, win);
		XFlush(dpy);
		s_window_handle = (void*)win;

		if (SConfig::GetInstance().m_LocalCoreStartupParameter.bDisableScreenSaver)
			X11Utils::InhibitScreensaver(dpy, win, true);

#if defined(HAVE_XRANDR) && HAVE_XRANDR
		XRRConfig = new X11Utils::XRRConfiguration(dpy, win);
#endif

		if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
		{
			// make a blank cursor
			Pixmap Blank;
			XColor DummyColor;
			char ZeroData[1] = { 0 };
			Blank = XCreateBitmapFromData(dpy, win, ZeroData, 1, 1);
			blankCursor = XCreatePixmapCursor(dpy, Blank, Blank, &DummyColor, &DummyColor, 0, 0);
			XFreePixmap(dpy, Blank);
			XDefineCursor(dpy, win, blankCursor);
		}
	}
Example #11
0
bool XPlatformWindow::setup_gcs() {
  // create 3 gc's and set their attributes
  unsigned long valuemask = 0;
  XGCValues values;
  _gc = XCreateGC(_display, _xwindow, valuemask, &values);
  
  XSetFont(_display, _gc, _font_info->fid);
  XSetForeground(_display, _gc, BlackPixel(_display, _screen_num));
  XSetBackground(_display, _gc, WhitePixel(_display, _screen_num));
  
  // 16x16 grey stipple pixmap (16x16 is preferred stipple size)
  const int grey_width = 16;
  const int grey_height = 16;
  static char grey_bits[] = {
    0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa,
    0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa,
    0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa};
  Pixmap stipple = XCreateBitmapFromData(_display, _xwindow, grey_bits,
                                         grey_width, grey_height);
  XSetStipple(_display, _gc, stipple);
  
  _black= BlackPixel(_display, _screen_num);
  _white= WhitePixel(_display, _screen_num);
  _is_mono = DefaultDepth(_display, _screen_num) == 1;
  if (_is_mono)
    _red= _yellow= _gray= _black;
  else {
    Colormap cmap= DefaultColormap(_display, _screen_num);
    XColor col1, col2;
    _red= XAllocNamedColor(_display, cmap, "red", &col1, &col2)
      ? col1.pixel : _black;
    _yellow= XAllocNamedColor(_display, cmap, "gold", &col1, &col2)
      ? col1.pixel : _black;
    _gray= XAllocNamedColor(_display, cmap, "gray", &col1, &col2)
      ? col1.pixel : _black;
  }
  return true;
}
Example #12
0
void	InitX(void)
{
	int	screen, dum;
	Pixmap	check;

	display = XOpenDisplay("");
	screen = DefaultScreen(display);
	cmap = DefaultColormap(display, screen);

	white = WhitePixel(display, screen);
	black = BlackPixel(display, screen);
	
	XGetGeometry(display, DefaultRootWindow(display),
		     &root, &dum, &dum, &width, &height, (unsigned int *)&dum, &depth);
	
	rootmap = XCreatePixmap(display, root, width, height, depth);
	cutmap = XCreatePixmap(display, root, width, height, depth);
	
	scratch = XCreateWindow(display, root, 0, 0, WINW, WINH, 0, depth,
			    InputOutput, CopyFromParent, 0, NULL);
	XSelectInput(display, scratch,
		     ExposureMask | KeyPressMask | PointerMotionMask |
		     ButtonPressMask | ButtonReleaseMask);
	XMapRaised(display, scratch);
	scratchmap = XCreatePixmap(display, root, WINW, WINH, depth);
	
	gc = XCreateGC(display, root, 0, 0);
	XSetSubwindowMode(display, gc, IncludeInferiors);
	
	shadow_gc = XCreateGC(display, root, 0, 0);
	XSetFillStyle(display, shadow_gc, FillStippled);
	check = XCreateBitmapFromData(display, root, check_bits, check_width, check_height);
	XSetStipple(display, shadow_gc, check);

	XGrabButton(display, Button1, Mod1Mask, DefaultRootWindow(display), False,
		    PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
		    GrabModeAsync, GrabModeAsync, DefaultRootWindow(display), None);
}
Example #13
0
int
main(int argc, char **argv)
{
	Widget	lbl ;
	Pixmap	xlogo ;

	XtSetLanguageProc(NULL,NULL,NULL) ;

	topLevel = XtVaAppInitialize(&app_ctx, "Test", NULL,0, &argc,argv,
		NULL,NULL) ;

	lbl = XtCreateManagedWidget("lbl",xmLabelWidgetClass, topLevel,NULL,0);

	XtRealizeWidget(topLevel) ;

	xlogo = XCreateBitmapFromData(XtDisplay(lbl), XtWindow(lbl),
		(const char *)xlogo16_bits, xlogo16_width, xlogo16_height) ;

	XtVaSetValues(lbl,
		XmNlabelType, XmPIXMAP,
		XmNlabelPixmap, xlogo,
		0) ;

/* Note: the following values are the result of
 * querying the current geometry.
 */
{
static XtWidgetGeometry Expected[] = {
   CWWidth | CWHeight            ,  361,  690,   22,   17, 0,0,0, /* lbl */
};
/* toplevel should be replaced with to correct applicationShell */
PrintDetails(topLevel, Expected);
}
LessTifTestMainLoop(topLevel);

	exit(0) ;
}
Example #14
0
File: init.c Project: pierreN/wmfs
/** Init the graphic context
*/
static void
init_gc(void)
{
     XGCValues gcv;

     /* Bits sequences */
     const char pix_bits[] =
          {
               0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55,
               0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55,
               0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55,
               0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55
          };

     gc = DefaultGC(dpy, SCREEN);

     /* Stipple GC */
     gcv.function   = GXcopy;
     gcv.fill_style = FillStippled;
     gcv.stipple    = XCreateBitmapFromData(dpy, ROOT, pix_bits, 10, 4);
     gc_stipple     = XCreateGC(dpy, ROOT, GCFunction | GCFillStyle | GCStipple, &gcv);

     return;
}
Example #15
0
static Cursor motEmptyCursor(Ihandle* ih)
{
  /* creates an empty cursor */
  XColor cursor_color = {0L,0,0,0,0,0};
  char bitsnull[1] = {0x00};
  Pixmap pixmapnull;
  Cursor cur;

  pixmapnull = XCreateBitmapFromData(iupmot_display,
    XtWindow(ih->handle),
    bitsnull,
    1,1);

  cur = XCreatePixmapCursor(iupmot_display,
    pixmapnull,
    pixmapnull,
    &cursor_color,
    &cursor_color,
    0,0);

  XFreePixmap(iupmot_display, pixmapnull);

  return cur;
}
Example #16
0
/*
 * iconClearBitmap
 *
 * Clear a bitmap by filling it with zeros.
 */
static void
iconClearBitmap(
	Display		*display,
	Window		window,
	GC		graphicsContext,
	Pixmap		bitmap,
	int		width,
	int		height)
{
	int		xx, yy;
	static Pixmap	blankBitmap = NULL;

	if (blankBitmap == NULL) {
		blankBitmap = XCreateBitmapFromData(display, window,
			(char *)blankBits, blankWidth, blankHeight);
	}
	for (xx = 0; xx < width + blankWidth; xx += blankWidth) {
	        for (yy = 0; yy < height + blankHeight; yy += blankHeight) {
			XCopyArea(display, blankBitmap, bitmap,
				graphicsContext, 0, 0,
				blankWidth, blankHeight, xx, yy);
		}
	}
}
Example #17
0
/*******************************************************************************\
|* openXwindow																   *|
\*******************************************************************************/
void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bits, int pixmask_width, int pixmask_height) {

	unsigned int	borderwidth = 1;
	XClassHint		classHint;
	char			*display_name = NULL;
	char			*wname = argv[0];
	XTextProperty	name;

	XGCValues		gcv;
	unsigned long	gcm;

	char			*geometry = NULL;

	int				dummy=0;
	int				i;

	for (i=1; argv[i]; i++) {
		if (!strcmp(argv[i], "-display"))
			display_name = argv[++i];
		else if (!strcmp(argv[i], "-geometry"))
			geometry = argv[++i];
	}

	if (!(display = XOpenDisplay(display_name))) {
		fprintf(stderr, "%s: can't open display %s\n",
						wname, XDisplayName(display_name));
		exit(1);
	}
	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.width = 64;
	mysizehints.height = 64;

	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);
	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(&wname, 1, &name) == 0) {
		fprintf(stderr, "%s: can't allocate window name\n", wname);
		exit(1);
	}

	XSetWMName(display, win, &name);

	/* 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 */

	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 = WithdrawnState;
	mywmhints.icon_window = iconwin;
	mywmhints.icon_x = mysizehints.x;
	mywmhints.icon_y = mysizehints.y;
	mywmhints.window_group = win;
	mywmhints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint;

	XSetWMHints(display, win, &mywmhints);

	XSetCommand(display, win, argv, argc);
	XMapWindow(display, win);
}
Example #18
0
void
MakeTopBox()
{
  Widget form, command, label; /* widgets. */
  Arg arglist[TOPARGS];		/* An argument list */
  Cardinal num_args = 0;	/* The number of arguments. */
  ManpageGlobals * man_globals;
  static char * full_size[] = {
    "topLabel", MANPAGE_BUTTON, NULL
  };
  static char * half_size[] = {
    HELP_BUTTON, QUIT_BUTTON, NULL
  };
  
/* create the top icon. */

  num_args = 0;
  XtSetArg(arglist[num_args], XtNiconPixmap,
	   XCreateBitmapFromData( XtDisplay(initial_widget), 
				 XtScreen(initial_widget)->root,
				 (char *)iconclosed_bits, iconclosed_width,
				 iconclosed_height));
  num_args++;
  XtSetArg(arglist[num_args], XtNtitle, resources.title);
  num_args++;
  XtSetArg(arglist[num_args], XtNiconic, resources.iconic);
  num_args++;
  top = XtCreatePopupShell(TOPBOXNAME, topLevelShellWidgetClass, 
			   initial_widget, arglist, num_args);

  form = XtCreateManagedWidget("form", formWidgetClass, top, 
			       NULL, (Cardinal) 0);

  label = XtCreateManagedWidget("topLabel", labelWidgetClass, form, 
			       NULL, (Cardinal) 0);

  num_args = 0;
  XtSetArg(arglist[num_args], XtNfromVert, label); num_args++;
  command = XtCreateManagedWidget(HELP_BUTTON, commandWidgetClass, form, 
				  arglist, num_args);

  /* use same vertical as help widget. */
  XtSetArg(arglist[num_args], XtNfromHoriz, command); num_args++;
  command = XtCreateManagedWidget(QUIT_BUTTON, commandWidgetClass, form, 
				  arglist, num_args);

  num_args = 0;
  XtSetArg(arglist[num_args], XtNfromVert, command); num_args++;
  command = XtCreateManagedWidget(MANPAGE_BUTTON, commandWidgetClass, form, 
				  arglist, num_args);

  help_widget = NULL;		/* We have not seen the help yet. */

  FormUpWidgets(form, full_size, half_size);

  XtRealizeWidget(top);
				/* add WM_COMMAND property */
  XSetCommand(XtDisplay(top), XtWindow(top), saved_argv, saved_argc);

  man_globals = (ManpageGlobals*) XtMalloc( (Cardinal) sizeof(ManpageGlobals));
  man_globals->label = NULL;
  man_globals->manpagewidgets.directory = NULL;
  man_globals->manpagewidgets.manpage = NULL;
  man_globals->manpagewidgets.box = NULL;
  man_globals->current_directory = 0;
  MakeSearchWidget(man_globals, top);
  MakeSaveWidgets(man_globals, top);

  SaveGlobals( (man_globals->This_Manpage = top), man_globals);
  XtMapWidget(top);
  AddCursor(top, resources.cursors.top);

/*
 * Set up ICCCM delete window.
 */
  wm_delete_window = XInternAtom(XtDisplay(top), "WM_DELETE_WINDOW",
				 False);
  XtOverrideTranslations
      (top, XtParseTranslationTable ("<Message>WM_PROTOCOLS: Quit()"));
  (void) XSetWMProtocols (XtDisplay(top), XtWindow(top),
			  &wm_delete_window, 1);
  

}
Example #19
0
void init_display(  )
{
	XClassHint       classHint;
	XTextProperty    name;
	XGCValues        gcv;
	unsigned long    gcm;
	int              dummy=0;
	char           * progname = PROGNAME;
	
	Pixel            back_pix;
	Pixel            fore_pix;

	display = XOpenDisplay( args_XDisplayName );
	
	if( display == NULL )
	{
		fprintf(stderr, "Can't open display\n" );
		free_and_exit( ERROR );
	}
	
	screen  = DefaultScreen(display);
	Root    = RootWindow(display, screen);
	d_depth = DefaultDepth(display, screen);
	x_fd    = XConnectionNumber(display);

	
	init_image ( );
	
	/* Create a window to hold the stuff */
	mysizehints.flags = USSize | USPosition;
	mysizehints.x = 0;
	mysizehints.y = 0;
	

	back_pix = WhitePixel( display, screen);
	fore_pix = BlackPixel( display, screen);

	XWMGeometry(display, screen, NULL, NULL, 1, &mysizehints, \
	            &mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy);
	
	mysizehints.width = 64;
	mysizehints.height = 64;
		
	win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y, \
	                          mysizehints.width, mysizehints.height, 1, fore_pix, back_pix);
	
	iconwin = XCreateSimpleWindow(display, win, mysizehints.x, mysizehints.y, \
	                              mysizehints.width, mysizehints.height, 1, fore_pix, back_pix);

	/* Activate hints */
	XSetWMNormalHints(display, win, &mysizehints);
	classHint.res_name = progname;
	classHint.res_class = progname;
	XSetClassHint(display, win, &classHint);

	XSelectInput(display, win, ButtonPressMask | ButtonReleaseMask | ExposureMask | StructureNotifyMask );
	XSelectInput(display, iconwin, ButtonPressMask | ButtonReleaseMask | ExposureMask | StructureNotifyMask );

	if (XStringListToTextProperty(&progname, 1, &name) == 0)
		PRINTQ(stderr, "%s: can't allocate window name\n", PROGNAME);
	

	XSetWMName(display, win, &name);
	
	/* 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 */
	
	pixmask = XCreateBitmapFromData(display, win, wmlaptop_mask_bits, wmlaptop_mask_width, wmlaptop_mask_height);

	XShapeCombineMask(display, win, ShapeBounding, 0, 0, pixmask, ShapeSet);
	XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet);
	
	/* ONLYSHAPE OFF */

	mywmhints.initial_state = WithdrawnState;
	mywmhints.icon_window = iconwin;
	mywmhints.icon_x = mysizehints.x;
	mywmhints.icon_y = mysizehints.y;
	mywmhints.window_group = win;
	mywmhints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint;

	XSetWMHints(display, win, &mywmhints);
	
	XMapWindow(display, win);
	
	
}
static void ui_confirm (char *message, int ok_only)

{
    Widget      form, picture, label;
    Arg		args[5];
    Widget	button;
    Cardinal	n;
    XEvent      event;

    /* Now create Popup */

    ui_cf_popup = 
	XtCreatePopupShell("confirmer", transientShellWidgetClass, ui_toplevel,
			   NULL, 0);
    form = 
	XtCreateManagedWidget("form", formWidgetClass, ui_cf_popup, NULL, 0);

    if (ok_only) {
	n = 0;
	XtSetArg(args[n], XtNborderWidth, 0); n++;
	XtSetArg(args[n], XtNbitmap, 
		 (Pixmap) XCreateBitmapFromData(ui_display, 
						XDefaultRootWindow(ui_display),
						exclamation_bits, 
						exclamation_width,
						exclamation_height)); n++;
    	picture = 
	    XtCreateManagedWidget("exclamation", labelWidgetClass, form, 
				  args, n);     

	n = 0;
	XtSetArg(args[n], XtNfromHoriz, picture); n++;
	XtSetArg(args[n], XtNborderWidth, 0); n++;
	XtSetArg(args[n], XtNlabel,     message); n++;
	label = XtCreateManagedWidget("confirmerMsg", labelWidgetClass, form, 
				      args, n);
    
	button = ui_xCreateButtonItem("ok", form, picture, label);
	XtAddCallback(button, XtNcallback, (XtCallbackProc) ui_cf_yesNoOk, 
		      (XtPointer) ((long)1));	

    } else {
	n = 0;
	XtSetArg(args[n], XtNborderWidth, 0); n++;
	XtSetArg(args[n], XtNbitmap, 
		 (Pixmap) XCreateBitmapFromData(ui_display, 
						XDefaultRootWindow(ui_display),
						stopIcon_bits, stopIcon_width,
						stopIcon_height)); n++;
	picture =
	    XtCreateManagedWidget("stop", labelWidgetClass, form, 
				  args, n);

	n = 0;
	XtSetArg(args[n], XtNfromHoriz, picture); n++;
	XtSetArg(args[n], XtNborderWidth, 0); n++;
	XtSetArg(args[n], XtNlabel,     message); n++;
	label = 
	    XtCreateManagedWidget("confirmerNsg", labelWidgetClass, form, 
				  args, n);

	button = ui_xCreateButtonItem("yes", form, picture, label);
	XtAddCallback(button, XtNcallback, (XtCallbackProc) ui_cf_yesNoOk, 
		      (XtPointer) ((long)1));	

	button = ui_xCreateButtonItem("no", form, button, label);
	XtAddCallback(button, XtNcallback, (XtCallbackProc) ui_cf_yesNoOk, 
		      (XtPointer) ((long)0));	
    }
    XawFormDoLayout(form, True);
    XtRealizeWidget(ui_cf_popup);
    
    /* now move the popup to the middle of the screen */
    {
	Window root;
	int    x, y;
	unsigned int borderWidth, depth, width, height;
	XWindowChanges xChange;
	
	(void) XGetGeometry(ui_display, XtWindow(ui_cf_popup),
			    &root, &x, &y, &width, &height, &borderWidth, &depth);
	
	xChange.x = 
	    (int) ((XDisplayWidth(ui_display, ui_screen) - width) / 2);
	xChange.y =
	    (int) ((XDisplayHeight(ui_display, ui_screen) - height) / 2);
	xChange.stack_mode = (int) Above;
	XConfigureWindow(ui_display, XtWindow(ui_cf_popup), 
			 CWX BIT_OR CWY BIT_OR CWStackMode, &xChange);
    }

    XtPopup(ui_cf_popup, XtGrabExclusive);
    ui_xDontResizeWidget(ui_cf_popup); 

    /* now enter the confirmer loop.
       Everthing behaves the same, because its an copy of XtAppMainLoop(), 
       but it stops UI from processing code from here back to the main loop.
       This is needed, because the confirmer should return values! */

    ui_cf_exit = FALSE;
    while (NOT ui_cf_exit) {
	XtAppNextEvent(ui_appContext, &event);
	(void) XtDispatchEvent(&event);
    }
}
Example #21
0
int
main(int argc, char **argv) {
  char curs[] = {0, 0, 0, 0, 0, 0, 0, 0};
	char buf[32], passwd[256];
	int num, screen;

#ifndef HAVE_BSD_AUTH
	const char *pws;
#endif
	unsigned int len;
	Bool running = True;
	Cursor invisible;
	Display *dpy;
	KeySym ksym;
	Pixmap pmap;
	Window root, w;
	XColor black, dummy;
	XEvent ev;
	XSetWindowAttributes wa;

	if((argc == 2) && !strcmp("-v", argv[1]))
		die("slock-"VERSION", © 2006-2008 Anselm R Garbe\n");
	else if(argc != 1)
		die("usage: slock [-vb]\n");
  
  backlight_of();
  
#ifndef HAVE_BSD_AUTH
	pws = get_password();
#endif

	if(!(dpy = XOpenDisplay(0)))
		die("slock: cannot open display\n");
	screen = DefaultScreen(dpy);
	root = RootWindow(dpy, screen);

	/* init */
	wa.override_redirect = 1;
	wa.background_pixel = BlackPixel(dpy, screen);
	w = XCreateWindow(dpy, root, 0, 0, DisplayWidth(dpy, screen), DisplayHeight(dpy, screen),
			0, DefaultDepth(dpy, screen), CopyFromParent,
			DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixel, &wa);
	XAllocNamedColor(dpy, DefaultColormap(dpy, screen), "black", &black, &dummy);
	pmap = XCreateBitmapFromData(dpy, w, curs, 8, 8);
	invisible = XCreatePixmapCursor(dpy, pmap, pmap, &black, &black, 0, 0);
	XDefineCursor(dpy, w, invisible);
	XMapRaised(dpy, w);
	for(len = 1000; len; len--) {
		if(XGrabPointer(dpy, root, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
			GrabModeAsync, GrabModeAsync, None, invisible, CurrentTime) == GrabSuccess)
			break;
		usleep(1000);
	}
	if((running = running && (len > 0))) {
		for(len = 1000; len; len--) {
			if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime)
				== GrabSuccess)
				break;
			usleep(1000);
		}
		running = (len > 0);
	}
	len = 0;
	XSync(dpy, False);

	/* main event loop */
	while(running && !XNextEvent(dpy, &ev)) {
		if(len == 0 && DPMSCapable(dpy)) {
			DPMSEnable(dpy);
			DPMSForceLevel(dpy, DPMSModeOff);
		}
		if(ev.type == KeyPress) {
			buf[0] = 0;
			num = XLookupString(&ev.xkey, buf, sizeof buf, &ksym, 0);
			if(IsKeypadKey(ksym)) {
				if(ksym == XK_KP_Enter)
					ksym = XK_Return;
				else if(ksym >= XK_KP_0 && ksym <= XK_KP_9)
					ksym = (ksym - XK_KP_0) + XK_0;
			}
			if(IsFunctionKey(ksym) || IsKeypadKey(ksym)
					|| IsMiscFunctionKey(ksym) || IsPFKey(ksym)
					|| IsPrivateKeypadKey(ksym))
				continue;
			switch(ksym) {
			case XK_Return:
				passwd[len] = 0;
#ifdef HAVE_BSD_AUTH
				running = !auth_userokay(getlogin(), NULL, "auth-xlock", passwd);
#else
				running = strcmp(crypt(passwd, pws), pws);
#endif
				if (running != 0)
					XBell(dpy, 100);
				len = 0;
				break;
			case XK_Escape:
				len = 0;
				break;
			case XK_BackSpace:
				if(len)
					--len;
				break;
			default:
				if(num && !iscntrl((int) buf[0]) && (len + num < sizeof passwd)) { 
					memcpy(passwd + len, buf, num);
					len += num;
				}
				break;
			}
		}
	}
	XUngrabPointer(dpy, CurrentTime);
	XFreePixmap(dpy, pmap);
	XDestroyWindow(dpy, w);
	XCloseDisplay(dpy);
  backlight_on();
	return 0;
}
Example #22
0
/*
 * The following function initializes a toplevel window.
 * It returns 0 if the initialization was successful,
 * or -1 if it couldn't initialize the double buffering routine.
 */
int Init_top(void)
{
    int					top_x, top_y;
    int					i;
    int					x, y;
    unsigned				w, h;
    unsigned long			values;
    int					top_flags;
    XGCValues				xgc;
    XSetWindowAttributes		sattr;
    unsigned long			mask;

    if (topWindow)
	fatal("Init_top called twice");

    if (Colors_init() == -1)
	return -1;

    radarDrawRectanglePtr = XFillRectangle;

    /*
     * Get toplevel geometry.
     */
    top_flags = 0;
    if (geometry != NULL && geometry[0] != '\0')
	mask = XParseGeometry(geometry, &x, &y, &w, &h);
    else
	mask = 0;

    if ((mask & WidthValue) != 0) {
	top_width = w;
	top_flags |= USSize;
    } else {
	top_width = DEF_TOP_WIDTH;
	top_flags |= PSize;
    }
    LIMIT(top_width, MIN_TOP_WIDTH, MAX_TOP_WIDTH);
    if ((mask & HeightValue) != 0) {
	top_height = h;
	top_flags |= USSize;
    } else {
	top_height = DEF_TOP_HEIGHT;
	top_flags |= PSize;
    }
    LIMIT(top_height, MIN_TOP_HEIGHT, MAX_TOP_HEIGHT);
    if ((mask & XValue) != 0) {
	if ((mask & XNegative) != 0)
	    top_x = DisplayWidth(dpy, DefaultScreen(dpy)) - top_width + x;
	else
	    top_x = x;
	top_flags |= USPosition;
    } else {
	top_x = (DisplayWidth(dpy, DefaultScreen(dpy)) - top_width) /2;
	top_flags |= PPosition;
    }
    if ((mask & YValue) != 0) {
	if ((mask & YNegative) != 0)
	    top_y = DisplayHeight(dpy, DefaultScreen(dpy)) - top_height + y;
	else
	    top_y = y;
	top_flags |= USPosition;
    } else {
	top_y = (DisplayHeight(dpy, DefaultScreen(dpy)) - top_height) /2;
	top_flags |= PPosition;
    }
    if (geometry != NULL) {
	free(geometry);
	geometry = NULL;
    }

    /*
     * Create toplevel window (we need this first so that we can create GCs)
     */
    mask = 0;
    /*old debug: sattr.background_pixel = colors[WHITE].pixel;*/
    sattr.background_pixel = colors[BLACK].pixel;
    mask |= CWBackPixel;
    sattr.border_pixel = colors[WHITE].pixel;
    mask |= CWBorderPixel;
    if (colormap != 0) {
	sattr.colormap = colormap;
	mask |= CWColormap;
    }
    if (ignoreWindowManager) {
	sattr.override_redirect = True;
	mask |= CWOverrideRedirect;
    }
    topWindow = XCreateWindow(dpy,
			      DefaultRootWindow(dpy),
			      top_x, top_y,
			      top_width, top_height,
			      0, (int)dispDepth,
			      InputOutput, visual,
			      mask, &sattr);
    XSelectInput(dpy, topWindow,
		 KeyPressMask | KeyReleaseMask
		 | FocusChangeMask | StructureNotifyMask);
    Init_disp_prop(dpy, topWindow, top_width, top_height,
		   top_x, top_y, top_flags);
    if (kdpy) {
	int scr = DefaultScreen(kdpy);
	keyboardWindow = XCreateSimpleWindow(kdpy,
					     DefaultRootWindow(kdpy),
					     top_x, top_y,
					     top_width, top_height,
					     0, 0, BlackPixel(dpy, scr));
	XSelectInput(kdpy, keyboardWindow,
		     KeyPressMask | KeyReleaseMask | FocusChangeMask);
	Init_disp_prop(kdpy, keyboardWindow, top_width, top_height,
		       top_x, top_y, top_flags);
    }

    /*
     * Create item bitmaps
     */
    for (i = 0; i < NUM_ITEMS; i++)
	itemBitmaps[i]
	    = XCreateBitmapFromData(dpy, topWindow,
				    (char *)itemBitmapData[i].data,
				    ITEM_SIZE, ITEM_SIZE);

    /*
     * Creates and initializes the graphic contexts.
     */
    xgc.line_width = 0;
    xgc.line_style = LineSolid;
    xgc.cap_style = CapButt;
    xgc.join_style = JoinMiter;		/* I think this is fastest, is it? */
    xgc.graphics_exposures = False;
    values
	= GCLineWidth|GCLineStyle|GCCapStyle|GCJoinStyle|GCGraphicsExposures;

    messageGC	= XCreateGC(dpy, topWindow, values, &xgc);
    radarGC	= XCreateGC(dpy, topWindow, values, &xgc);
    buttonGC	= XCreateGC(dpy, topWindow, values, &xgc);
    scoreListGC	= XCreateGC(dpy, topWindow, values, &xgc);
    textGC	= XCreateGC(dpy, topWindow, values, &xgc);
    talkGC	= XCreateGC(dpy, topWindow, values, &xgc);
    motdGC	= XCreateGC(dpy, topWindow, values, &xgc);
    gameGC	= XCreateGC(dpy, topWindow, values, &xgc);
    XSetBackground(dpy, gameGC, colors[BLACK].pixel);

    /*
     * Set fonts
     */
    gameFont
	= Set_font(dpy, gameGC, gameFontName, "gameFont");
    messageFont
	= Set_font(dpy, messageGC, messageFontName, "messageFont");
    scoreListFont
	= Set_font(dpy, scoreListGC, scoreListFontName, "scoreListFont");
    buttonFont
	= Set_font(dpy, buttonGC, buttonFontName, "buttonFont");
    textFont
	= Set_font(dpy, textGC, textFontName, "textFont");
    talkFont
	= Set_font(dpy, talkGC, talkFontName, "talkFont");
    motdFont
	= Set_font(dpy, motdGC, motdFontName, "motdFont");

    XSetState(dpy, gameGC,
	      WhitePixel(dpy, DefaultScreen(dpy)),
	      BlackPixel(dpy, DefaultScreen(dpy)),
	      GXcopy, AllPlanes);
    XSetState(dpy, radarGC,
	      WhitePixel(dpy, DefaultScreen(dpy)),
	      BlackPixel(dpy, DefaultScreen(dpy)),
	      GXcopy, AllPlanes);
    XSetState(dpy, messageGC,
	      WhitePixel(dpy, DefaultScreen(dpy)),
	      BlackPixel(dpy, DefaultScreen(dpy)),
	      GXcopy, AllPlanes);
    XSetState(dpy, buttonGC,
	      WhitePixel(dpy, DefaultScreen(dpy)),
	      BlackPixel(dpy, DefaultScreen(dpy)),
	      GXcopy, AllPlanes);
    XSetState(dpy, scoreListGC,
	      WhitePixel(dpy, DefaultScreen(dpy)),
	      BlackPixel(dpy, DefaultScreen(dpy)),
	      GXcopy, AllPlanes);

    if (dbuf_state->type == COLOR_SWITCH)
	XSetPlaneMask(dpy, gameGC, dbuf_state->drawing_planes);

    return 0;
}
Example #23
0
void setWindowHints(Window win, char **argv, int argc, char *window_name,
                    char *icon_name, char *res_name, char *res_class)
{
  XSizeHints *size_hints;
  XWMHints *wm_hints;
  XClassHint *class_hints;
  XTextProperty windowName, iconName;

  XSelectInput(Spw_Dpy, win,
               ButtonPressMask | ButtonReleaseMask
               | KeyPressMask | KeyReleaseMask
               | ExposureMask 
               );

  /*
   * Allocate and set the the Size hints in a friendly way
   */

  if ( !(size_hints = XAllocSizeHints()) )
     {
     fprintf(stderr,"Not enough memory\n");
     exit(-1);
     }
  /*
   *  What things we will be setting.  Position and size refer to
   *  if the user set the values (via a resource file for example)
   *  or if the program set the values.
   */
  size_hints->flags = 
                      PPosition   | /* Program specified position      */
                      PSize       | /* Program specified size          */
                      PBaseSize   | /* Program specified base size     */
                      0;

  /*
   *  Now set the values.
   */
  size_hints->base_width = Spw_WindowWidth;
  size_hints->base_height = Spw_WindowHeight;
   
  /*
   * Allocate and set the the Window Manager hints in a friendly way.
   * This is probably the most critical to set correctly as some
   * WMs (olwm) are REALLY picky about setting them correctly and
   * hose you if you don't.  Like, for example, not sending you any
   * keypresses.
   */
  if ( !(wm_hints = XAllocWMHints()) )
     {
     fprintf(stderr,"Not enough memory\n");
     exit(-1);
     }

  /*
   *  What hints we will be setting
   */
  wm_hints->flags = InputHint        | /* Setting if we expect input  */
                    StateHint        | /* What initial state to be in */
                    IconPixmapHint   | /* Set the Icon pixmap         */
                    IconMaskHint     | /* Set the Icon Shape Mask     */
                    0;

  wm_hints->input = TRUE;                /* InputHint */
  wm_hints->initial_state = NormalState  /* or IconicState */; /* StateHint */

  wm_hints->icon_pixmap = XCreateBitmapFromData(Spw_Dpy,
                                                Spw_mainWindow,
                                                (char *)sbXcityfly_icon_bits,
                                                sbXcityfly_icon_width,
                                                sbXcityfly_icon_height);
  wm_hints->icon_mask = XCreateBitmapFromData(Spw_Dpy,
                                              Spw_mainWindow,
                                              (char *)sbXcityfly_iconMask_bits,
                                              sbXcityfly_iconMask_width,
                                              sbXcityfly_iconMask_height);
  /*
   * Allocate and set the the Class hints in a friendly way
   */
  if ( !(class_hints = XAllocClassHint()) )
     {
     fprintf(stderr,"Not enough memory\n");
     exit(-1);
     }
   /*
    *  Not much to say this is about it for class hints....
    */
  class_hints->res_name = res_name;
  class_hints->res_class = res_class;
  
  /*
   * Convert names into X strings
   */

  if ( XStringListToTextProperty( &window_name, 1, &windowName) == 0 )
     {
     fprintf(stderr,"Couldn't create string\n");
     exit(-1);
     }
  if ( XStringListToTextProperty( &icon_name, 1, &iconName) == 0 )
     {
     fprintf(stderr,"Couldn't create string\n");
     exit(-1);
     }

  /*
   * Finally we can set the properities.
   * This is supposedly the "correct" call.  Most of the
   * others like SetWMHints are obsolete.
   */

  XSetWMProperties(Spw_Dpy, win, &windowName, &iconName,
                   argv, argc, size_hints, wm_hints, class_hints);

}
    root = RootWindow(awt_display, DefaultScreen(awt_display));
    fcolor.flags = DoRed | DoGreen | DoBlue;
    fcolor.red = ((fc >> 16) & 0x000000ff) << 8;
    fcolor.green = ((fc >> 8) & 0x000000ff) << 8;
    fcolor.blue = ((fc >> 0) & 0x000000ff) << 8;
    XAllocColor(awt_display, defaultConfig->awt_cmap, &fcolor);
    bcolor.flags = DoRed | DoGreen | DoBlue;
    bcolor.red = ((bc >> 16) & 0x000000ff) << 8;
    bcolor.green = ((bc >> 8) & 0x000000ff) << 8;
    bcolor.blue = ((bc >> 0) & 0x000000ff) << 8;
    XAllocColor(awt_display, defaultConfig->awt_cmap, &bcolor);

    /* Create source pixmap. */
    sourceBits = (char *)(*env)->GetPrimitiveArrayCritical(env, xorMask, NULL);
    source = XCreateBitmapFromData(awt_display, root, sourceBits,
                                         width, height);

    /* Create mask pixmap */
    maskBits = (char *)(*env)->GetPrimitiveArrayCritical(env, andMask, NULL);
    mask = XCreateBitmapFromData(awt_display, root, maskBits,
                                       width, height);

    /* Create cursor */
    cursor = XCreatePixmapCursor(awt_display, source, mask, &fcolor, &bcolor,
                                 xHotSpot, yHotSpot);

    /* Free resources */
    XFreePixmap(awt_display, source);
    XFreePixmap(awt_display, mask);

    (*env)->ReleasePrimitiveArrayCritical(env, xorMask, sourceBits, JNI_ABORT);
Example #25
0
int main(int argc, char **argv)
{
    char	    *file_name = 0;
    Cardinal	    i;
    static Arg	    labelArgs[] = {
			{XtNlabel, (XtArgVal) pageLabel},
    };
    XtAppContext    xtcontext;
    Arg		    topLevelArgs[2];
    Widget          entry;
    Arg		    pageNumberArgs[1];
    int		    page_number;

    toplevel = XtAppInitialize(&xtcontext, "GXditview",
			    options, XtNumber (options),
 			    &argc, argv, fallback_resources, NULL, 0);
    if (argc > 2
	|| (argc == 2 && (!strcmp(argv[1], "-help")
			  || !strcmp(argv[1], "--help"))))
	Syntax(argv[0]);

    XtGetApplicationResources(toplevel, (XtPointer)&app_resources,
			      resources, XtNumber(resources),
			      NULL, (Cardinal) 0);
    if (app_resources.print_command)
	strcpy(current_print_command, app_resources.print_command);

    XtAppAddActions(xtcontext, xditview_actions, XtNumber (xditview_actions));

    XtSetArg (topLevelArgs[0], XtNiconPixmap,
	      XCreateBitmapFromData (XtDisplay (toplevel),
				     XtScreen(toplevel)->root,
				     (char *)xdit_bits,
				     xdit_width, xdit_height));
				    
    XtSetArg (topLevelArgs[1], XtNiconMask,
	      XCreateBitmapFromData (XtDisplay (toplevel),
				     XtScreen(toplevel)->root,
				     (char *)xdit_mask_bits, 
				     xdit_mask_width, xdit_mask_height));
    XtSetValues (toplevel, topLevelArgs, 2);
    if (argc > 1)
	file_name = argv[1];

    /*
     * create the menu and insert the entries
     */
    simpleMenu = XtCreatePopupShell ("menu", simpleMenuWidgetClass, toplevel,
				    NULL, 0);
    for (i = 0; i < XtNumber (menuEntries); i++) {
	entry = XtCreateManagedWidget(menuEntries[i].name, 
				      smeBSBObjectClass, simpleMenu,
				      NULL, (Cardinal) 0);
	XtAddCallback(entry, XtNcallback, menuEntries[i].function, NULL);
    }

    paned = XtCreateManagedWidget("paned", panedWidgetClass, toplevel,
				    NULL, (Cardinal) 0);
    viewport = XtCreateManagedWidget("viewport", viewportWidgetClass, paned,
				     NULL, (Cardinal) 0);
    dvi = XtCreateManagedWidget ("dvi", dviWidgetClass, viewport, NULL, 0);
    page = XtCreateManagedWidget ("label", labelWidgetClass, paned,
					labelArgs, XtNumber (labelArgs));
    XtSetArg (pageNumberArgs[0], XtNpageNumber, &page_number);
    XtGetValues (dvi, pageNumberArgs, 1);
    if (file_name)
	NewFile (file_name);
    /* NewFile modifies current_file_name, so do this here. */
    if (app_resources.filename)
	strcpy(current_file_name, app_resources.filename);
    XtRealizeWidget (toplevel);
    if (file_name)
	SetPageNumber (page_number);
    XtAppMainLoop(xtcontext);
    return 0;
}
Example #26
0
void set_up_bitmaps()
{
	/*	first-stage pixmaps -- each different colored part must be created
		from a mono bitmap, and then laid atop each other to make the
		final multi-color pixmap.
	*/
	Pixmap playerbit[PLAYERPHASES][PLAYERPARTS];
	Pixmap burnbit[BURNDIRECTIONS][BURNPARTS];
	Pixmap firebit[FIREPHASES][FIREPARTS];
	Pixmap sweeperbit[SWEEPERPHASES][SWEEPERPARTS];
	Pixmap guardbit[GUARDPARTS];
	Pixmap guardlightbit[GUARDLIGHTS];
	Pixmap guardflamebit[GUARDDIRECTIONS][GUARDFLAMEPARTS];
	Pixmap explodebit[EXPLODEFRAMES];
	Pixmap skelbit[EXPLODEFRAMES];
	Pixmap doorbit[DOORFRAMES][DOORPARTS];
	Pixmap fuelbit[FUELPARTS];
	Pixmap keybit[KEYPARTS];
	Pixmap extramanbit;

	int	i, j, k, g[GUARDLIGHTS];

	/*	Each of the following sections essentially does this:
			create and erase the main pixmap
			create all the secondary pixmaps from bitmap data
			copy the secondary pixmaps onto the main pixmap with the
				proper color
	*/

	/*	Player pixmaps
	*/
	for(i=0; i<PLAYERPHASES; i++) {
		playerpix[i] = XCreatePixmap(display, gamewindow, PLAYERWIDTH,
										PLAYERHEIGHT, depth);
		XFillRectangle(display, playerpix[i], ctable[CBLACK].smallgc,
						0, 0, PLAYERWIDTH, PLAYERHEIGHT);
		for(j=0; j<PLAYERPARTS; j++) {
			playerbit[i][j] = XCreateBitmapFromData(display, gamewindow,
													player_bits[i][j],
													PLAYERWIDTH,
													PLAYERHEIGHT);
			XCopyPlane(display, playerbit[i][j], playerpix[i],
						ctable[playercolor[j]].smallgc, 0, 0,
						PLAYERWIDTH, PLAYERHEIGHT, 0, 0, 1);
		}
	}

	/*	Pixmaps for the jetpack flame
	*/
	for(i=0; i<BURNDIRECTIONS; i++) {
		burnpix[i] = XCreatePixmap(display, gamewindow, BURNWIDTH,
									BURNHEIGHT, depth);
		XFillRectangle(display, burnpix[i], ctable[CBLACK].smallgc,
						0, 0, BURNWIDTH, BURNHEIGHT);
		for(j=0; j<BURNPARTS; j++) {
			burnbit[i][j] = XCreateBitmapFromData(display, gamewindow,
													burn_bits[i][j],
													BURNWIDTH,
													BURNHEIGHT);
			XCopyPlane(display, burnbit[i][j], burnpix[i],
						ctable[burncolor[j]].smallgc, 0, 0,
						BURNWIDTH, BURNHEIGHT, 0, 0, 1);
		}
	}

	/* Wall sweeper pixmaps (very pretty)
	*/
	for(i=0; i<SWEEPERPHASES; i++) {
		sweeperpix[i] = XCreatePixmap(display, gamewindow, SWEEPERWIDTH,
										SWEEPERHEIGHT, depth);
		XFillRectangle(display, sweeperpix[i], ctable[CBLACK].smallgc,
						0, 0, SWEEPERWIDTH, SWEEPERHEIGHT);
		for(j=0; j<SWEEPERPARTS; j++) {
			sweeperbit[i][j] = XCreateBitmapFromData(display, gamewindow,
														sweeper_bits[i][j],
														SWEEPERWIDTH, 
														SWEEPERHEIGHT);
			XCopyPlane(display, sweeperbit[i][j], sweeperpix[i],
						ctable[sweepcolor[j]].smallgc, 0, 0,
						SWEEPERWIDTH, SWEEPERHEIGHT, 0, 0, 1);
		}
	}

	/*	Fireball pixmaps
	*/
	for(i=0; i<FIREPHASES; i++) {
		firepix[i] = XCreatePixmap(display, gamewindow, FIREWIDTH,
									FIREHEIGHT, depth);
		XFillRectangle(display, firepix[i], ctable[CBLACK].smallgc,
						0, 0, FIREWIDTH, FIREHEIGHT);
		for(j=0; j<FIREPARTS; j++) {
			firebit[i][j] = XCreateBitmapFromData(display, gamewindow,
													fire_bits[i][j],
													FIREWIDTH,
													FIREHEIGHT);
			XCopyPlane(display, firebit[i][j], firepix[i],
						ctable[firecolor[j]].smallgc, 0, 0,
						FIREWIDTH, FIREHEIGHT, 0, 0, 1);
		}
	}

	/*	Guard pixmaps. These are a little odd because of the random
		blinking light sequences. There are three sets of lights on the
		guard, and each can be on or off. This makes 8 different frames,
		but to cut down on bitmap data, I only made the three light
		bitmaps rather than 8.
	*/
	for(i=0; i<GUARDPARTS; i++) {
		guardbit[i] = XCreateBitmapFromData(display, gamewindow,
											guard_bits[i], GUARDWIDTH,
											GUARDHEIGHT);
		for(j=0; j<GUARDDIRECTIONS; j++) {
			guardflamebit[j][i] = XCreateBitmapFromData(display, gamewindow,
													guard_flame_bits[j][i],
													GUARDWIDTH,
													GUARDHEIGHT);
		}
	}
	for(i=0; i<GUARDLIGHTS; i++) {
		guardlightbit[i] = XCreateBitmapFromData(display, gamewindow,
											guard_light_bits[i],
											GUARDWIDTH, GUARDHEIGHT);
	}
	for(i=0; i<GUARDDIRECTIONS; i++) {
		for(j=0; j<GUARDPHASES; j++) {
			guardpix[i][j] = XCreatePixmap(display, gamewindow, GUARDWIDTH,
											GUARDHEIGHT, depth);
			XFillRectangle(display, guardpix[i][j],
							ctable[CBLACK].smallgc, 0, 0,
							GUARDWIDTH, GUARDHEIGHT);
			for(k=0; k<GUARDPARTS; k++) {
				XCopyPlane(display, guardbit[k], guardpix[i][j],
							ctable[guardcolor[k]].smallgc,
							0, 0, GUARDWIDTH, GUARDHEIGHT, 0, 0, 1);
			}
			for(k=0; k<GUARDFLAMEPARTS; k++) {
				XCopyPlane(display, guardflamebit[i][k], guardpix[i][j],
							ctable[guardflamecolor[k]].smallgc,
							0, 0, GUARDWIDTH, GUARDHEIGHT, 0, 0, 1);
			}
			/*	This initialization will need to be expanded if I add more
				lights.
			*/
			g[2] = j / 4;
			g[1] = (j % 4) / 2;
			g[0] = (j % 4) % 2;
			for(k=0; k<GUARDLIGHTS; k++) {
				if(g[k]) XCopyPlane(display, guardlightbit[k], guardpix[i][j],
									ctable[guardlightcolor].smallgc,
									0, 0, GUARDWIDTH, GUARDHEIGHT, 0, 0, 1);
			}
		}
	}

	/*	Player explosion pixmaps
	*/
	for(i=0; i<EXPLODEFRAMES; i++) {
		explodepix[i] = XCreatePixmap(display, gamewindow, EXPLODEWIDTH,
										EXPLODEHEIGHT, depth);
		XFillRectangle(display, explodepix[i], ctable[CBLACK].smallgc,
						0, 0, EXPLODEWIDTH, EXPLODEHEIGHT);
		explodebit[i] = XCreateBitmapFromData(display, gamewindow,
												explode_bits[i],
												EXPLODEWIDTH,
												EXPLODEHEIGHT);
		skelbit[i] = XCreateBitmapFromData(display, gamewindow,
												skel_bits[i], SKELWIDTH,
												SKELHEIGHT);
		XCopyPlane(display, explodebit[i], explodepix[i],
					ctable[explodecolor].smallgc, 0, 0, EXPLODEWIDTH,
					EXPLODEHEIGHT, 0, 0, 1);
		XCopyPlane(display, skelbit[i], explodepix[i],
					ctable[skelcolor].smallgc, 0, 0, SKELWIDTH,
					SKELHEIGHT, (EXPLODEWIDTH - SKELWIDTH) / 2,
					(EXPLODEWIDTH - SKELWIDTH) / 2, 1);
	}

	/*	Fuel pod pixmap
	*/
	fuelpix = XCreatePixmap(display, gamewindow, FUELWIDTH, FUELHEIGHT,
							depth);
	XFillRectangle(display, fuelpix, ctable[CBLACK].smallgc, 0, 0,
					FUELWIDTH, FUELHEIGHT);
	for(i=0; i<FUELPARTS; i++) {
			fuelbit[i] = XCreateBitmapFromData(display, gamewindow,
												fuel_bits[i],
												FUELWIDTH, FUELHEIGHT);
			XCopyPlane(display, fuelbit[i], fuelpix,
						ctable[fuelcolor[i]].smallgc, 0, 0,
						FUELWIDTH, FUELHEIGHT, 0, 0, 1);
	}

	/*	Key pixmap
	*/
	keypix = XCreatePixmap(display, gamewindow, KEYWIDTH, KEYHEIGHT,
							depth);
	XFillRectangle(display, keypix, ctable[CBLACK].smallgc, 0, 0,
					KEYWIDTH, KEYHEIGHT);
	for(i=0; i<KEYPARTS; i++) {
			keybit[i] = XCreateBitmapFromData(display, gamewindow,
												key_bits[i], KEYWIDTH,
												KEYHEIGHT);
			XCopyPlane(display, keybit[i], keypix,
						ctable[keycolor[i]].smallgc, 0, 0,
						KEYWIDTH, KEYHEIGHT, 0, 0, 1);
	}

	/*	Door pixmaps. The only difference in frames is the color, but I
		wanted it this way in case I want to animate the door in the
		future.
	*/
	for(i=0; i<DOORFRAMES; i++) {
		doorpix[i] = XCreatePixmap(display, gamewindow, DOORWIDTH,
									DOORHEIGHT, depth);
		XFillRectangle(display, doorpix[i], ctable[CBLACK].smallgc,
						0, 0, DOORWIDTH, DOORHEIGHT);
		for(j=0; j<DOORPARTS; j++) {
			doorbit[i][j] = XCreateBitmapFromData(display, gamewindow,
													door_bits[i][j], 
													DOORWIDTH, DOORHEIGHT);
			XCopyPlane(display, doorbit[i][j], doorpix[i],
						ctable[doorcolor[i][j]].smallgc, 0, 0, 
						DOORWIDTH, DOORHEIGHT, 0, 0, 1);
		}
	}

	/*	Extra player pixmap
	*/
	extramanpix = XCreatePixmap(display, gamewindow, EXTRAMANWIDTH,
								EXTRAMANHEIGHT, depth);
	XFillRectangle(display, extramanpix, ctable[CBLACK].smallgc,
					0, 0, EXTRAMANWIDTH, EXTRAMANHEIGHT);
	extramanbit = XCreateBitmapFromData(display, gamewindow, extraman_bits,
										EXTRAMANWIDTH, EXTRAMANHEIGHT);
	XCopyPlane(display, extramanbit, extramanpix,
				ctable[extramancolor].smallgc,
				0, 0, EXTRAMANWIDTH, EXTRAMANHEIGHT, 0, 0, 1);

	/*	free all the temporary pixmaps
	*/
	for(i=0; i<PLAYERPHASES; i++) {
		for(j=0; j<PLAYERPARTS; j++) {
			XFreePixmap(display, playerbit[i][j]);
		}
	}
	for(i=0; i<BURNDIRECTIONS; i++) {
		for(j=0; j<BURNPARTS; j++) {
			XFreePixmap(display, burnbit[i][j]);
		}
	}
	for(i=0; i<FIREPHASES; i++) {
		for(j=0; j<FIREPARTS; j++) {
			XFreePixmap(display, firebit[i][j]);
		}
	}
	for(i=0; i<SWEEPERPHASES; i++) {
		for(j=0; j<SWEEPERPARTS; j++) {
			XFreePixmap(display, sweeperbit[i][j]);
		}
	}
	for(i=0; i<GUARDPARTS; i++) {
		XFreePixmap(display, guardbit[i]);
	}
	for(i=0; i<GUARDLIGHTS; i++) {
		XFreePixmap(display, guardlightbit[i]);
	}
	for(i=0; i<GUARDDIRECTIONS; i++) {
		for(j=0; j<GUARDFLAMEPARTS; j++) {
			XFreePixmap(display, guardflamebit[i][j]);
		}
	}
	for(i=0; i<EXPLODEFRAMES; i++) {
		XFreePixmap(display, explodebit[i]);
		XFreePixmap(display, skelbit[i]);
	}
	for(i=0; i<DOORFRAMES; i++) {
		for(j=0; j<DOORPARTS; j++) {
			XFreePixmap(display, doorbit[i][j]);
		}
	}
	for(i=0; i<FUELPARTS; i++) {
		XFreePixmap(display, fuelbit[i]);
	}
	for(i=0; i<KEYPARTS; i++) {
		XFreePixmap(display, keybit[i]);
	}
	XFreePixmap(display, extramanbit);
}
Example #27
0
File: window.c Project: hirkmt/sxiv
void win_open(win_t *win)
{
	win_env_t *e;
	XClassHint classhint;
	XColor col;
	char none_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
	Pixmap none;
	int gmask;

	if (win == NULL)
		return;

	e = &win->env;

	/* determine window offsets, width & height */
	if (options->geometry == NULL)
		gmask = 0;
	else
		gmask = XParseGeometry(options->geometry, &win->x, &win->y,
		                       &win->w, &win->h);
	if ((gmask & WidthValue) != 0)
		win->sizehints.flags |= USSize;
	else
		win->w = WIN_WIDTH;
	if ((gmask & HeightValue) != 0)
		win->sizehints.flags |= USSize;
	else
		win->h = WIN_HEIGHT;
	if ((gmask & XValue) != 0) {
		if ((gmask & XNegative) != 0) {
			win->x += e->scrw - win->w;
			win->sizehints.win_gravity = NorthEastGravity;
		}
		win->sizehints.flags |= USPosition;
	} else {
		win->x = (e->scrw - win->w) / 2;
	}
	if ((gmask & YValue) != 0) {
		if ((gmask & YNegative) != 0) {
			win->y += e->scrh - win->h;
			if (win->sizehints.win_gravity == NorthEastGravity)
				win->sizehints.win_gravity = SouthEastGravity;
			else
				win->sizehints.win_gravity = SouthWestGravity;
		}
		win->sizehints.flags |= USPosition;
	} else {
		win->y = (e->scrh - win->h) / 2;
	}

	win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr),
	                          win->x, win->y, win->w, win->h, 0,
	                          e->depth, InputOutput, e->vis, 0, None);
	if (win->xwin == None)
		die("could not create window");
	
	XSelectInput(e->dpy, win->xwin,
	             ExposureMask | ButtonReleaseMask | ButtonPressMask |
	             KeyPressMask | PointerMotionMask | StructureNotifyMask);

	carrow = XCreateFontCursor(e->dpy, XC_left_ptr);
	chand = XCreateFontCursor(e->dpy, XC_fleur);
	cwatch = XCreateFontCursor(e->dpy, XC_watch);

	if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), "black",
	                     &col, &col) == 0)
	{
		die("could not allocate color: black");
	}
	none = XCreateBitmapFromData(e->dpy, win->xwin, none_data, 8, 8);
	cnone = XCreatePixmapCursor(e->dpy, none, none, &col, &col, 0, 0);

	gc = XCreateGC(e->dpy, win->xwin, 0, None);

	win_set_title(win, "sxiv");

	classhint.res_class = "Sxiv";
	classhint.res_name = options->res_name != NULL ? options->res_name : "sxiv";
	XSetClassHint(e->dpy, win->xwin, &classhint);

	XSetWMProtocols(e->dpy, win->xwin, &wm_delete_win, 1);

	win->h -= win->bar.h;
	win_update_sizehints(win);

	XMapWindow(e->dpy, win->xwin);
	XFlush(e->dpy);

	if (options->fullscreen)
		win_toggle_fullscreen(win);
}
Example #28
0
int main(int argc, char **argv)
{
  unsigned long valuemask;		/* mask for create windows */
  XSetWindowAttributes attributes;	/* attributes for create windows */
  void InternUsefulAtoms(void);
  void InitVariables(void);
  int  i, len;
  extern int x_fd;
  char *display_string;
  char message[255];
  Bool single = False;
  Bool option_error = FALSE;
  MenuRoot *mr;

  g_argv = argv;
  g_argc = argc;

  OpenConsole();
  DBUG("main", "Entered, about to parse args");

  for (i = 1; i < argc; i++) {
    if (strncasecmp(argv[i], "-debug", 6) == 0) {
      debugging = True;
    } else if (strncasecmp(argv[i], "-s", 2) == 0) {
      single = True;
    } else if (strncasecmp(argv[i], "-d", 2) == 0) {
      if (++i >= argc)
	usage();
      display_name = argv[i];
    } else if (strncasecmp(argv[i], "-f", 2) == 0) {
      if (++i >= argc)
	usage();
      config_command = (char *) malloc(6 + strlen(argv[i]));
      strcpy(config_command, "Read ");
      strcat(config_command, argv[i]);
      free_config_command = True;
    } else if (strncasecmp(argv[i], "-cmd", 4) == 0) {
      if (++i >= argc)
	usage();
      config_command = argv[i];
    } else if (strncasecmp(argv[i], "-file", 5) == 0) {
      if (++i >= argc)
	usage();
      output_file = argv[i];
    } else if (strncasecmp(argv[i], "-h", 2) == 0) {
      usage();
      exit(0);
    } else if (strncasecmp(argv[i], "-blackout", 9) == 0) {
      Blackout = True;
    } else if (strncasecmp(argv[i], "-version", 8) == 0) {
      fvwm_msg(INFO, "main", "Fvwm95 Version %s compiled on %s at %s\n",
	       VERSION, __DATE__, __TIME__);
    } else {
      fvwm_msg(ERR, "main", "Unknown option: `%s'\n", argv[i]);
      option_error = TRUE;
    }
  }

  DBUG("main", "Done parsing args");

  if (option_error) {
    usage();
  }

  DBUG("main", "Installing signal handlers");

  newhandler(SIGINT);
  newhandler(SIGHUP);
  newhandler(SIGQUIT);
  newhandler(SIGTERM);
  signal(SIGUSR1, Restart);
  signal(SIGPIPE, DeadPipe);

  ReapChildren();

  if (!(dpy = XOpenDisplay(display_name))) {
    fvwm_msg(ERR, "main", "can't open display %s",
	     XDisplayName(display_name));
    exit(1);
  }
  Scr.screen = DefaultScreen(dpy);
  Scr.NumberOfScreens = ScreenCount(dpy);

  master_pid = getpid();

  if (!single) {
    int myscreen = 0;
    char *cp;

    strcpy(message, XDisplayString(dpy));

    XCloseDisplay(dpy);

    for (i = 1; i < Scr.NumberOfScreens; i++) {
      if (fork() == 0) {
	myscreen = i;
	break;
      }
    }
    /*
     * Truncate the string 'whatever:n.n' to 'whatever:n',
     * and then append the screen number.
     */
    cp = strchr(message, ':');
    if (cp != NULL) {
      cp = strchr(cp, '.');
      if (cp != NULL)
	*cp = '\0';		/* truncate at display part */
    }
    sprintf(message + strlen(message), ".%d", myscreen);
    dpy = XOpenDisplay(message);
    Scr.screen = myscreen;
    Scr.NumberOfScreens = ScreenCount(dpy);
  }

  x_fd = XConnectionNumber(dpy);
  fd_width = GetFdWidth();

  if (fcntl(x_fd, F_SETFD, 1) == -1) {
    fvwm_msg(ERR, "main", "close-on-exec failed");
    exit(1);
  }

  /*  Add a DISPLAY entry to the environment, in case we were started
   *  with fvwm -display term:0.0
   */
  len = strlen(XDisplayString(dpy));
  display_string = safemalloc(len + 10);
  sprintf(display_string, "DISPLAY=%s", XDisplayString(dpy));
  putenv(display_string);

  /* Add a HOSTDISPLAY environment variable, which is the same as
   * DISPLAY, unless display = :0.0 or unix:0.0, in which case the full
   * host name will be used for ease in networking . */

  /* Note: Can't free the rdisplay_string after putenv, because it
   * becomes part of the environment! */

  if (strncmp(display_string, "DISPLAY=:", 9) == 0) {
    char client[MAXHOSTNAME], *rdisplay_string;

    mygethostname(client, MAXHOSTNAME);
    rdisplay_string = safemalloc(len + 14 + strlen(client));
    sprintf(rdisplay_string, "HOSTDISPLAY=%s:%s", client,
	    &display_string[9]);
    putenv(rdisplay_string);
  } else if (strncmp(display_string, "DISPLAY=unix:", 13) == 0) {
    char client[MAXHOSTNAME], *rdisplay_string;

    mygethostname(client, MAXHOSTNAME);
    rdisplay_string = safemalloc(len + 14 + strlen(client));
    sprintf(rdisplay_string, "HOSTDISPLAY=%s:%s", client,
	    &display_string[13]);
    putenv(rdisplay_string);
  } else {
    char *rdisplay_string;

    rdisplay_string = safemalloc(len + 14);
    sprintf(rdisplay_string, "HOSTDISPLAY=%s", XDisplayString(dpy));
    putenv(rdisplay_string);
  }

  Scr.Root = RootWindow(dpy, Scr.screen);
  if (Scr.Root == None) {
    fvwm_msg(ERR, "main", "Screen %d is not a valid screen",
	     (char *) Scr.screen);
    exit(1);
  }

#ifdef SHAPE
  ShapesSupported =
      XShapeQueryExtension(dpy, &ShapeEventBase, &ShapeErrorBase);
#endif	/* SHAPE */

  InternUsefulAtoms();

  /* Make sure property priority colors is empty */
  XChangeProperty(dpy, Scr.Root, _XA_MIT_PRIORITY_COLORS,
		  XA_CARDINAL, 32, PropModeReplace, NULL, 0);

  XSetErrorHandler((XErrorHandler) CatchRedirectError);
  XSetIOErrorHandler((XIOErrorHandler) CatchFatal);

  XSelectInput(dpy, Scr.Root,
	       LeaveWindowMask | EnterWindowMask | PropertyChangeMask |
	       SubstructureRedirectMask | KeyPressMask |
	       SubstructureNotifyMask |
	       ButtonPressMask | ButtonReleaseMask);

  XSync(dpy, 0);

  XSetErrorHandler((XErrorHandler) FvwmErrorHandler);

  BlackoutScreen();

  CreateCursors();
  InitVariables();
  InitEventHandlerJumpTable();
  initModules();

  InitPictureCMap(dpy, Scr.Root);	/* for the pixmap cache... */

  Scr.gray_bitmap =
      XCreateBitmapFromData(dpy, Scr.Root, g_bits, g_width, g_height);

  DBUG("main", "Setting up rc file defaults...");
  SetRCDefaults();

  DBUG("main", "Running config_command...");
  ExecuteFunction(config_command, NULL, &Event, C_ROOT, -1);
  DBUG("main", "Done running config_command");

/*
  CaptureAllWindows();
  MakeMenus();
*/

#if 0	/* this seems to cause problems for FvwmCpp/M4 startup actually */
  /* if not a direct 'Read', we'll capture all windows here, in case cmd
     fails we'll still have defaults */
  if (strncasecmp(config_command, "Read", 4) != 0 &&
      strncasecmp(config_command, "PipeRead", 8) != 0) {
    /* so if cmd (FvwmM4/Cpp most likely) fails, we can still have
       borders & stuff... */
    StartupStuff();
  }
#endif	/* 0 */

  if (free_config_command) {
    free(config_command);
  }

  if (Scr.d_depth < 2) {
    Scr.gray_pixmap =
	XCreatePixmapFromBitmapData(dpy, Scr.Root, g_bits, g_width,
				    g_height, Scr.WinColors.fore,
				    Scr.WinColors.back, Scr.d_depth);
    Scr.light_gray_pixmap =
	XCreatePixmapFromBitmapData(dpy, Scr.Root, l_g_bits, l_g_width,
				    l_g_height, Scr.WinColors.fore,
				    Scr.WinColors.back, Scr.d_depth);
  }

  /* create a window which will accept the keyboard focus when no other 
     windows have it */
  attributes.event_mask = KeyPressMask | FocusChangeMask;
  attributes.override_redirect = True;
  Scr.NoFocusWin = XCreateWindow(dpy, Scr.Root, -10, -10, 10, 10, 0, 0,
				 InputOnly, CopyFromParent,
				 CWEventMask | CWOverrideRedirect,
				 &attributes);
  XMapWindow(dpy, Scr.NoFocusWin);

  SetMWM_INFO(Scr.NoFocusWin);

  XSetInputFocus(dpy, Scr.NoFocusWin, RevertToParent, CurrentTime);

  XSync(dpy, 0);
  if (debugging)
    XSynchronize(dpy, 1);

  Scr.SizeStringWidth = XTextWidth(Scr.StdFont.font,
				   " +8888 x +8888 ", 15);
  attributes.border_pixel = Scr.WinColors.fore;
  attributes.background_pixel = Scr.WinColors.back;
  attributes.bit_gravity = NorthWestGravity;
  attributes.save_under = True;
  valuemask = (CWBorderPixel | CWBackPixel | CWBitGravity | CWSaveUnder);

  /* create the window for coordinates */
  Scr.SizeWindow = XCreateWindow(dpy, Scr.Root,
				 Scr.MyDisplayWidth / 2 -
				 (Scr.SizeStringWidth +
				  SIZE_HINDENT * 2) / 2,
				 Scr.MyDisplayHeight / 2 -
				 (Scr.StdFont.height +
				  SIZE_VINDENT * 2) / 2,
				 (unsigned int) (Scr.SizeStringWidth +
						 SIZE_HINDENT * 2),
				 (unsigned int) (Scr.StdFont.height +
						 SIZE_VINDENT * 2),
				 (unsigned int) 0, 0,
				 (unsigned int) CopyFromParent,
				 (Visual *) CopyFromParent,
				 valuemask, &attributes);

#ifndef NON_VIRTUAL
  initPanFrames();
#endif

  XGrabServer(dpy);

#ifndef NON_VIRTUAL
  checkPanFrames();
#endif
  XUngrabServer(dpy);
  UnBlackoutScreen();
  DBUG("main", "Entering HandleEvents loop...");
  HandleEvents();
  DBUG("main", "Back from HandleEvents loop?  Exiting...");

  return 0;
}
Example #29
0
void main(int argc, char **argv)
{
      int i=21,forcer=0; /* init variables. */
      Display *p_disp;
      FILE *fpo;
      char text[]="MultiSliceRTPsession0";

    /* Create the top-level shell widget and initialize the toolkit */
    argcount = 0;
    XtSetArg(args[argcount], XmNallowShellResize, False); argcount++;
    XtSetArg(args[argcount], XmNtitle,       APP_TITLE); argcount++;
    XtSetArg(args[argcount], XmNiconName,   ICON_TITLE); argcount++;
    top_level = XtAppInitialize(&app, "Slice", NULL, 0,
                                &argc, argv, NULL, args, argcount);
    theAppName = argv[0];

    #include "command_slice.c"
 
    /* Create the main window widget */
    argcount = 0;
/*    XtSetArg(args[argcount], XmNwidth ,  WIDTH); argcount++;
      XtSetArg(args[argcount], XmNheight, HEIGHT); argcount++; */
    main_window = XmCreateRowColumn(top_level, "Main", args, argcount);
    XtManageChild(main_window);
    p_disp=XtDisplay(main_window);
if(forcer != 1)
{
/*      if(XFetchBytes(p_disp,&i) != NULL){ if(i==21){
      fprintf(stderr,"\nOnly one copy of MultiSlice can run at one time...\nslice -forceload will forcibly load a second copy.\nSelf-Destruct Initialised...\nSecond copy destructed...OK\n");
      XtCloseDisplay(XtDisplay(main_window));exit(-1);}}
      i=21; XStoreBytes(p_disp,text,i); */
if((fopen("slicetempyhsTN","r")) != 0){
      fprintf(stderr,"\nOnly one copy of MultiSlice RTP can run at one time...\nslice -forceload will forcibly load a second copy if \n the first one was terminated incorrectly.\n");
      system("cat slicetempyhsTN");
      fprintf(stderr,"\nSelf-destruct initialised...\nSecond copy destructed...OK\n");
      XtCloseDisplay(XtDisplay(main_window));exit(-1);}}
      i=0;
      strcpy(tempfileold,"slicetempyhsT");
      strcpy(tempfilenew,"slicetempyhsT");
      addcharac[1]='\0';
      strcat(tempfilenew,addcharac);
      system("echo First copy of MultiSliceRTP started at :- >slicetempyhsTN");
      system("date >>slicetempyhsTN");
      for(i=0;i<11;i++){yhs_filename[i]=0;squash[i]=0;squash[i+10]=0;} 
      i=0;
fprintf(stderr,"\n\n-------------------MultiSlice RTP Status Messages-------------------\n");
fprintf(stderr,"Launching application...");
system("date");
fprintf(stderr,"Load and select file(s) to process...\n");

    /* Create the main menu */ 
    create_main_menu(main_window);

 
    /* Create the drawing area 1 */
    argcount = 0;
    XtSetArg(args[argcount], XmNwidth ,  IMAGE_WIDTH); argcount++;
    XtSetArg(args[argcount], XmNheight, IMAGE_HEIGHT); argcount++;
    draw_1 = XmCreateDrawingArea(top_level, "draw_1", args, argcount);
/*    XtManageChild(draw_1); */
 
    /* Create the drawing area 2 */
    argcount = 0;
    XtSetArg(args[argcount], XmNwidth ,  IMAGE_WIDTH); argcount++;
    XtSetArg(args[argcount], XmNheight, IMAGE_HEIGHT); argcount++;
    draw_2 = XmCreateDrawingArea(top_level, "draw_2", args, argcount);
/*    XtManageChild(draw_2); */
 
    /* Create a watch cursor */
    theCursor = XCreateFontCursor(XtDisplay(main_window), XC_watch);

    /* Create the icon window for the application */
    app_icon = XCreateBitmapFromData(XtDisplay(top_level),
                                     DefaultRootWindow(XtDisplay(top_level)),
                                     icon_bits, icon_width, icon_height);
    argcount = 0;
    XtSetArg(args[argcount], XmNiconPixmap, app_icon); argcount++;
    XtSetValues(top_level, args, argcount);

  
    XtAppAddTimeOut(app,2*1000,update_time,NULL); 
 
    /* Realize all widgets */
    XtRealizeWidget(top_level);

    /* Make some initializations */
    setup_display (top_level);
    create_region_list(&region_list);


    /* Event handling loop--keep processing events until done */
    XtAppMainLoop(app);


}
Example #30
0
void X11_MainLoop()
{
	bool fullscreen = SConfig::GetInstance().m_LocalCoreStartupParameter.bFullscreen;
	while (Core::GetState() == Core::CORE_UNINITIALIZED)
		updateMainFrameEvent.Wait();

	Display *dpy = XOpenDisplay(0);
	Window win = (Window)Core::GetWindowHandle();
	XSelectInput(dpy, win, KeyPressMask | FocusChangeMask);

	if (SConfig::GetInstance().m_LocalCoreStartupParameter.bDisableScreenSaver)
		X11Utils::InhibitScreensaver(dpy, win, true);

#if defined(HAVE_XRANDR) && HAVE_XRANDR
	X11Utils::XRRConfiguration *XRRConfig = new X11Utils::XRRConfiguration(dpy, win);
#endif

	Cursor blankCursor = None;
	if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
	{
		// make a blank cursor
		Pixmap Blank;
		XColor DummyColor;
		char ZeroData[1] = {0};
		Blank = XCreateBitmapFromData (dpy, win, ZeroData, 1, 1);
		blankCursor = XCreatePixmapCursor(dpy, Blank, Blank, &DummyColor, &DummyColor, 0, 0);
		XFreePixmap (dpy, Blank);
		XDefineCursor(dpy, win, blankCursor);
	}

	if (fullscreen)
	{
		X11Utils::EWMH_Fullscreen(dpy, _NET_WM_STATE_TOGGLE);
#if defined(HAVE_XRANDR) && HAVE_XRANDR
		XRRConfig->ToggleDisplayMode(True);
#endif
	}

	// The actual loop
	while (running)
	{
		XEvent event;
		KeySym key;
		for (int num_events = XPending(dpy); num_events > 0; num_events--)
		{
			XNextEvent(dpy, &event);
			switch(event.type)
			{
				case KeyPress:
					key = XLookupKeysym((XKeyEvent*)&event, 0);
					if (key == XK_Escape)
					{
						if (Core::GetState() == Core::CORE_RUN)
						{
							if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
								XUndefineCursor(dpy, win);
							Core::SetState(Core::CORE_PAUSE);
						}
						else
						{
							if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
								XDefineCursor(dpy, win, blankCursor);
							Core::SetState(Core::CORE_RUN);
						}
					}
					else if ((key == XK_Return) && (event.xkey.state & Mod1Mask))
					{
						fullscreen = !fullscreen;
						X11Utils::EWMH_Fullscreen(dpy, _NET_WM_STATE_TOGGLE);
#if defined(HAVE_XRANDR) && HAVE_XRANDR
						XRRConfig->ToggleDisplayMode(fullscreen);
#endif
					}
					else if (key >= XK_F1 && key <= XK_F8)
					{
						int slot_number = key - XK_F1 + 1;
						if (event.xkey.state & ShiftMask)
							State::Save(slot_number);
						else
							State::Load(slot_number);
					}
					else if (key == XK_F9)
						Core::SaveScreenShot();
					else if (key == XK_F11)
						State::LoadLastSaved();
					else if (key == XK_F12)
					{
						if (event.xkey.state & ShiftMask)
							State::UndoLoadState();
						else
							State::UndoSaveState();
					}
					break;
				case FocusIn:
					rendererHasFocus = true;
					if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor &&
							Core::GetState() != Core::CORE_PAUSE)
						XDefineCursor(dpy, win, blankCursor);
					break;
				case FocusOut:
					rendererHasFocus = false;
					if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
						XUndefineCursor(dpy, win);
					break;
			}
		}
		if (!fullscreen)
		{
			Window winDummy;
			unsigned int borderDummy, depthDummy;
			XGetGeometry(dpy, win, &winDummy,
					&SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowXPos,
					&SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowYPos,
					(unsigned int *)&SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowWidth,
					(unsigned int *)&SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowHeight,
					&borderDummy, &depthDummy);
		}
		usleep(100000);
	}

#if defined(HAVE_XRANDR) && HAVE_XRANDR
	delete XRRConfig;
#endif
	if (SConfig::GetInstance().m_LocalCoreStartupParameter.bDisableScreenSaver)
		X11Utils::InhibitScreensaver(dpy, win, false);

	if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
		XFreeCursor(dpy, blankCursor);
	XCloseDisplay(dpy);
	Core::Stop();
}