コード例 #1
0
ファイル: cursor.c プロジェクト: Cougar/pwm
void set_cursor(Window win, int cursor)
{
	XDefineCursor(wglobal.dpy, win, cursors[cursor]);
}
コード例 #2
0
ファイル: slock.c プロジェクト: paraxor/slock
static Lock* lockscreen(Display *dpy, int screen) {
	char curs[] = {0, 0, 0, 0, 0, 0, 0, 0};
	unsigned int len;
	Lock *lock;
	XColor color, dummy;
	XSetWindowAttributes wa;
	Cursor invisible;

	if(dpy == NULL || screen < 0) {
		return NULL;
	}

	lock = malloc(sizeof(Lock));
	if(lock == NULL) {
		return NULL;
	}

	lock->screen = screen;

	lock->root = RootWindow(dpy, lock->screen);

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

	running &= (len > 0);
	if(!running) {
		unlockscreen(dpy, lock);
		lock = NULL;
	}
	else {
		XSelectInput(dpy, lock->root, SubstructureNotifyMask);
		unsigned int value = (unsigned int) (opacity * 0xffffffff);
		XChangeProperty(dpy, lock->win, XInternAtom(dpy, "_NET_WM_WINDOW_OPACITY", False), XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &value, 1L);
		XSync(dpy, False);
	}

	return lock;
}
コード例 #3
0
ファイル: misc.c プロジェクト: aosm/X11apps
FILE *
Format(ManpageGlobals * man_globals, char * entry)
{
  FILE * file = NULL;
#ifdef HAS_MKSTEMP
  int fd;
#endif
  Widget manpage = man_globals->manpagewidgets.manpage;
  char cmdbuf[BUFSIZ], tmp[BUFSIZ], filename[BUFSIZ], error_buf[BUFSIZ];
  char path[BUFSIZ], sect[BUFSIZ];
  XEvent event;
  Position x,y;			/* location to pop up the
				   "would you like to save" widget. */

#ifndef HAS_MKSTEMP
  if ( !UncompressUnformatted(man_globals, entry, filename) ) {
#else
  if ( !UncompressUnformatted(man_globals, entry, filename, &file) ) {
#endif
    /* We Really could not find it, this should never happen, yea right. */
    snprintf(error_buf, sizeof(error_buf),
	     "Could not open manual page, %s", entry);
    PopupWarning(man_globals, error_buf);
    XtPopdown( XtParent(man_globals->standby) );
    return(NULL);
  }

#ifndef HAS_MKSTEMP
  if ((file = fopen(filename, "r")) != NULL) {
#else
  if (file != NULL) {
#endif
    char line[BUFSIZ];

    if (fgets(line, sizeof(line), file) != NULL) {
	if (strncmp(line, ".so ", 4) == 0) {
	  line[strlen(line) - 1] = '\0';
	  fclose(file);
	  unlink(filename);
	  if (line[4] != '/') {
	    char *ptr = NULL;

	    strcpy(tmp, entry);
	    if ((ptr = rindex(tmp, '/')) != NULL) {
	      *ptr = '\0';
	      if ((ptr = rindex(tmp, '/')) != NULL)
		ptr[1] = '\0';
	    }
	  }
	  else
	    *tmp = '\0';
	  snprintf(filename, sizeof(filename), "%s%s", tmp, line + 4);

	  return (Format(man_globals, filename));
	}
    }
    fclose(file);
  }

  Popup(XtParent(man_globals->standby), XtGrabExclusive);
  while ( !XCheckTypedWindowEvent(XtDisplay(man_globals->standby),
				  XtWindow(man_globals->standby),
				  Expose, &event) );
  XtDispatchEvent( &event );
  XFlush(XtDisplay(man_globals->standby));

  strcpy(tmp,MANTEMP);		          /* Get a temp file. */
#ifndef HAS_MKSTEMP
  (void) mktemp(tmp);
#else
  fd = mkstemp(tmp);
  file = fdopen(fd, "r");
#endif
  strcpy(man_globals->tempfile, tmp);

  ParseEntry(entry, path, sect, NULL);

#ifndef HANDLE_ROFFSEQ
#ifndef HAS_MKSTEMP
  snprintf(cmdbuf, sizeof(cmdbuf), "cd %s ; %s %s %s > %s %s", path, TBL,
	  filename, FORMAT, man_globals->tempfile, "2> /dev/null");
#else
  snprintf(cmdbuf, sizeof(cmdbuf), "cd %s ; %s %s %s >> %s %s", path, TBL,
	  filename, FORMAT, man_globals->tempfile, "2> /dev/null");
#endif
#else
  /* Handle more flexible way of specifying the formatting pipeline */
  if (! ConstructCommand(cmdbuf, path, filename, man_globals->tempfile)) {
     sprintf(error_buf, "Constructed command was too long!");
     PopupWarning(man_globals, error_buf);
     file = NULL;
  }
  else
#endif /* HANDLE_ROFFSEQ */

  if(system(cmdbuf) != 0) {	/* execute search. */
    snprintf(error_buf, sizeof(error_buf),
	    "Something went wrong trying to run the command: %s", cmdbuf);
    PopupWarning(man_globals, error_buf);
    file = NULL;
  }
  else {
#ifndef HAS_MKSTEMP
    if ((file = fopen(man_globals->tempfile,"r")) == NULL) {
      sprintf(error_buf, "Something went wrong in retrieving the %s",
	      "temp file, try cleaning up /tmp");
      PopupWarning(man_globals, error_buf);
    }
    else {
#endif

      XtPopdown( XtParent(man_globals->standby) );

      if ( (man_globals->save == NULL) ||
	   (man_globals->manpagewidgets.manpage == NULL) )
	unlink(man_globals->tempfile);
      else {
	char * ptr, catdir[BUFSIZ];

	/*
	 * If the catdir is writeable then ask the user if he/she wants to
	 * write the man page to it.
	 */

	strcpy(catdir, man_globals->save_file);
	if ( (ptr = rindex(catdir, '/')) != NULL) {
	  *ptr = '\0';

	  if ( access(catdir, W_OK) != 0 )
	    unlink(man_globals->tempfile);
	  else {
	    x = (Position) Width(man_globals->manpagewidgets.manpage)/2;
	    y = (Position) Height(man_globals->manpagewidgets.manpage)/2;
	    XtTranslateCoords(manpage, x, y, &x, &y);
	    PositionCenter( man_globals->save, (int) x, (int) y, 0, 0, 0, 0);
	    XtPopup( man_globals->save, XtGrabExclusive);
	  }
	}
	else
	  unlink(man_globals->tempfile);
      }
#ifndef HAS_MKSTEMP
    }
#endif
  }

 /*
  * If the original was compressed or in another format, delete temporary file.
  */
  if (man_globals->deletetempfile) 
    unlink(filename);

  return(file);
}

#ifdef HANDLE_ROFFSEQ
/*      Function Name: ConstructCommand
 *      Description: Constructs the pipeline of commands necessary to format
 *                   a manual page.
 *      Arguments: cmdbuf - the buffer into which to write the command
 *                 path - the directory in which the original man page resides
 *                 filename - the (uncompressed) manpage source file
 *                 tempfile - the name of a temporary file to direct the final
 *                  output of the pipeline into
 *      Returns: TRUE if the command fit into the buffer, FALSE if it would
 *               be too long (more than BUFSIZ characters)
 */
static Boolean
ConstructCommand(cmdbuf, path, filename, tempfile)
   char *cmdbuf, *path, *filename, *tempfile;
{
   /* The original code did the following to produce a command line:
    *   sprintf(cmdbuf,"cd %s ; %s %s %s > %s %s", path, TBL,
    *      filename, FORMAT, man_globals->tempfile, "2> /dev/null");
    * We are more flexible and follow more or less the algorithm used
    * by the Linux man command:
    *  + Obtain a string of letters from the following sources in order
    *    of preference:
    *    + a command line option (not implemented in xman; it's probably not
    *      useful)
    *    + the first line of the manpage source, if it is of the form:
    *      '\" <string>
    *    + the MANROFFSEQ environment variable
    *    + a default string; this is "".
    *  + Interpret the string as a pipeline of filters:
    *    + e = eqn   g = grap   p = pic   t = tbl   v = vgrind   r = refer
    *  + zsoelim is always run as the first preprocessor in any case.
    *
    * Strictly speaking we should save a catpage iff the string comes
    * from the file or is the default.
    *
    * You'll notice that we format a man page into ASCII text output and then
    * attempt to interpret things like L^HL as bold and so forth. This
    * is so obviously the Wrong Thing it's untrue.
    */
   char *c = cmdbuf;           /* current posn in buffer */
   int left = BUFSIZ;          /* space left in buffer */
   int used;
   char *fmt;
   FILE *file;
   char fmtbuf[128];
   int gotfmt = 0;             /* set to 1 if we got a directive from source */
   char *fname = NULL;
#ifdef __UNIXOS2__
   int i;
#endif

   fmt = NULL;
   /* If you have a command line option that gives a setting for fmt,
      set it here. */

   if (!fmt) {
      /* This is the tricky bit: extract a format string from the source file
       * Annoyingly, filename might be relative or absolute. We cheat and
       * use system to get the thing to a known absoute filename.
       */
      if (filename[0] == '/') {
         fname = filename;
      } else {
         fname = malloc(strlen(path) + 1 + strlen(filename) + 1);
         if (!fname)
            return FALSE;
         sprintf(fname, "%s/%s", path, filename);
      }
      if ((file = fopen(fname, "r")) &&
          (fgets(fmtbuf, sizeof(fmtbuf), file)) &&
          (!memcmp(fmtbuf, "'\\\" ", 4))) {
                              /* that's squote-backslash-dquote-space */
         int len;
         fmt = fmtbuf + 3;
         len = strlen(fmt);
         if (len && (fmt[len-1] == '\n')) {
            fmt[len-1] = 0;
            gotfmt++;
         }
      }
      if (fname && fname != filename)
         free(fname);
      if (!gotfmt)                                /* not there or some error */
      {
         fmt = getenv("MANROFFSEQ");
      }
   }

   if (!fmt)
   {
      fmt = DEFAULT_MANROFFSEQ;
   }


   /* Start with the first fixed part of the command line */
#ifdef __UNIXOS2__
   for (i = 0; i < strlen(path); i++) {
     if (path[i] == '/')
       path[i] = '\\';
   }
   used = snprintf(c, left, "cd %s & %s %s ", path, ZSOELIM, filename);
#else
   used = snprintf(c, left, "cd %s; %s %s ", path, ZSOELIM, filename);
#endif
   left -= used;
   c += used;
   if (left <= 1)
      return (FALSE);

   /* Now add preprocessors of the form '| processor' */
   for ( ; *fmt; fmt++)
   {
      char *filter;
      switch (*fmt)
      {
         case 'e':
            filter = EQN;
            break;
         case 'g':
            filter = GRAP;
            break;
         case 'p':
            filter = PIC;
            break;
         case 't':
            filter = TBL;
            break;
         case 'v':
            filter = VGRIND;
            break;
         case 'r':
            filter = REFER;
            break;
         default:
            filter = NULL;
            break;
      }
      if (filter)
      {
         used = snprintf(c, left, " | %s ", filter);
         left -= used;
         c += used;
         if (left <= 1)
            return (FALSE);
      }
   }

   /* Now add the fixed trailing part 'formatprog > tempfile 2> /dev/null' */
#ifdef __UNIXOS2__
   used = snprintf(c, left, " | %s > %s 2>NUL", FORMAT, tempfile);
#else
#ifndef HAS_MKSTEMP
   used = snprintf(c, left, " | %s > %s 2>/dev/null", FORMAT, tempfile);
#else
   used = snprintf(c, left, " | %s >> %s 2>/dev/null", FORMAT, tempfile);
#endif
#endif /* __UNIXOS2__ */
   left -= used;
   if (left <= 1)
      return (FALSE);

   return (TRUE);
}
#endif /* HANDLE_ROFFSEQ */

/*	Function Name: UncompressUnformatted
 *	Description: Finds an uncompressed unformatted manual page.
 *	Arguments: man_globals - the psuedo global structure.
 *                 entry - the manual page entry.
 * RETURNED        filename - location to put the name of the file.
 *	Returns: TRUE if the file was found.
 */

static Boolean
#ifndef HAS_MKSTEMP
UncompressUnformatted(ManpageGlobals * man_globals, char * entry,
		      char * filename)
#else
UncompressUnformatted(ManpageGlobals * man_globals, char * entry,
		      char * filename, FILE **file)
#endif
{
  char path[BUFSIZ], page[BUFSIZ], section[BUFSIZ], input[BUFSIZ];
  int len_cat = strlen(CAT), len_man = strlen(MAN);
#if defined(SMAN) && defined(SFORMAT)
  int len_sman = strlen(SMAN);
#endif

  ParseEntry(entry, path, section, page);

  man_globals->bzip2 = FALSE;
  man_globals->lzma = FALSE;

#if defined(__OpenBSD__) || defined(__NetBSD__)
  /*
   * look for uncompressed file in machine subdir first
   */
  snprintf(filename, BUFSIZ, "%s/%s%s/%s/%s", path, MAN,
	  section + len_cat, MACHINE, page);
  if ( access( filename, R_OK ) == 0 ) {
    man_globals->compress = FALSE;
    man_globals->gzip = FALSE;
    man_globals->deletetempfile = FALSE;
    snprintf(man_globals->save_file, sizeof(man_globals->save_file),
    	     "%s/%s%s/%s/%s", path, CAT, section + len_cat, MACHINE, page);
    return(TRUE);
  }
 /*
  * Then for compressed files in an uncompressed directory.
  */
  snprintf(input, sizeof(input), "%s.%s", filename, COMPRESSION_EXTENSION);
#ifndef HAS_MKSTEMP
  if ( UncompressNamed(man_globals, input, filename) ) {
#else
  if ( UncompressNamed(man_globals, input, filename, file) ) {
#endif
    man_globals->compress = TRUE;
    man_globals->deletetempfile = TRUE;
    snprintf(man_globals->save_file, sizeof(man_globals->save_file),
	     "%s/%s%s/%s.%s", path, CAT, section + len_cat, page, 
	     COMPRESSION_EXTENSION);
    return(TRUE);
  }
#ifdef GZIP_EXTENSION
  else {
    snprintf(input, sizeof(input), "%s.%s", filename, GZIP_EXTENSION);
#ifndef HAS_MKSTEMP
    if ( UncompressNamed(man_globals, input, filename) ) {
#else
    if ( UncompressNamed(man_globals, input, filename, file) ) {
#endif
      man_globals->compress = TRUE;
      man_globals->gzip = TRUE;
      man_globals->deletetempfile = TRUE;
      snprintf(man_globals->save_file, sizeof(man_globals->save_file),
	       "%s/%s%s/%s.%s", path, CAT, section + len_cat, page,
	       GZIP_EXTENSION);
      return(TRUE);
    }
  }
#endif /* GZIP_EXTENSION */
#endif /* __OpenBSD__ || __NetBSD__ */

#ifdef BZIP2_EXTENSION
 {
    sprintf(input, "%s.%s", filename, BZIP2_EXTENSION);
#ifndef HAS_MKSTEMP
    if ( UncompressNamed(man_globals, input, filename) ) {
#else
    if ( UncompressNamed(man_globals, input, filename, file) ) {
#endif
      man_globals->compress = TRUE;
      man_globals->gzip = FALSE;
      man_globals->bzip2 = TRUE;
      sprintf(man_globals->save_file, "%s/%s%s/%s.%s", path,
	      CAT, section + len_cat, page, BZIP2_EXTENSION);
      return(TRUE);
    }
  }
#endif /* BZIP2_EXTENSION */

#ifdef LZMA_EXTENSION
 {
    sprintf(input, "%s.%s", filename, LZMA_EXTENSION);
#ifndef HAS_MKSTEMP
    if ( UncompressNamed(man_globals, input, filename) ) {
#else
    if ( UncompressNamed(man_globals, input, filename, file) ) {
#endif
      man_globals->compress = TRUE;
      man_globals->gzip = FALSE;
      man_globals->lzma = TRUE;
      sprintf(man_globals->save_file, "%s/%s%s/%s.%s", path,
	      CAT, section + len_cat, page, LZMA_EXTENSION);
      return(TRUE);
    }
  }
#endif /* LZMA_EXTENSION */

/*
 * Look for uncompressed file first.
 */

  snprintf(filename, BUFSIZ, "%s/%s%s/%s", path, MAN, section + len_man, page);
  if ( access( filename, R_OK ) == 0 ) {
    man_globals->compress = FALSE;
    man_globals->gzip = FALSE;
    man_globals->deletetempfile = FALSE;
    snprintf(man_globals->save_file, sizeof(man_globals->save_file), 
	     "%s/%s%s/%s", path, CAT, section + len_cat, page);
    return(TRUE);
  }

#if defined(SMAN) && defined(SFORMAT)
 /*
  * Look for uncompressed sgml file next.
  */

  snprintf(input, BUFSIZ, "%s/%s%s/%s", path, SMAN, section + len_sman, page);
#ifndef HAS_MKSTEMP
  if ( SgmlToRoffNamed(man_globals, input, filename) ) {
#else
  if ( SgmlToRoffNamed(man_globals, input, filename, file) ) {
#endif
    man_globals->compress = FALSE;
    man_globals->gzip = FALSE;
    man_globals->deletetempfile = TRUE;
    snprintf(man_globals->save_file, sizeof(man_globals->save_file),
            "%s/%s%s/%s", path, CAT, section + len_cat, page);
    return(TRUE);
  }
#endif

/*
 * Then for compressed files in an uncompressed directory.
 */

  snprintf(input, sizeof(input), "%s.%s", filename, COMPRESSION_EXTENSION);
#ifndef HAS_MKSTEMP
  if ( UncompressNamed(man_globals, input, filename) ) {
#else
  if ( UncompressNamed(man_globals, input, filename, file) ) {
#endif
    man_globals->compress = TRUE;
    man_globals->deletetempfile = TRUE;
    snprintf(man_globals->save_file, sizeof(man_globals->save_file),
	     "%s/%s%s/%s.%s", path, CAT, section + len_cat, page, 
	     COMPRESSION_EXTENSION);
    return(TRUE);
  }
#ifdef GZIP_EXTENSION
  else {
    snprintf(input, sizeof(input), "%s.%s", filename, GZIP_EXTENSION);
#ifndef HAS_MKSTEMP
    if ( UncompressNamed(man_globals, input, filename) ) {
#else
    if ( UncompressNamed(man_globals, input, filename, file) ) {
#endif	
      man_globals->compress = TRUE;
      man_globals->gzip = TRUE;
      man_globals->deletetempfile = TRUE;
      snprintf(man_globals->save_file, sizeof(man_globals->save_file),
	       "%s/%s%s/%s.%s", path, CAT, section + len_cat, page, 
	       GZIP_EXTENSION);
      return(TRUE);
    }
  }
#endif

#ifdef BZIP2_EXTENSION
  {
    sprintf(input, "%s.%s", filename, BZIP2_EXTENSION);
#ifndef HAS_MKSTEMP
    if ( UncompressNamed(man_globals, input, filename) ) {
#else
    if ( UncompressNamed(man_globals, input, filename, file) ) {
#endif	
      man_globals->compress = TRUE;
      man_globals->gzip = TRUE;
      sprintf(man_globals->save_file, "%s/%s%s/%s.%s", path,
	      CAT, section + len_cat, page, BZIP2_EXTENSION);
      return(TRUE);
    }
  }
#endif

#ifdef LZMA_EXTENSION
  {
    sprintf(input, "%s.%s", filename, LZMA_EXTENSION);
#ifndef HAS_MKSTEMP
    if ( UncompressNamed(man_globals, input, filename) ) {
#else
    if ( UncompressNamed(man_globals, input, filename, file) ) {
#endif	
      man_globals->compress = TRUE;
      man_globals->lzma = TRUE;
      sprintf(man_globals->save_file, "%s/%s%s/%s.%s", path,
	      CAT, section + len_cat, page, LZMA_EXTENSION);
      return(TRUE);
    }
  }
#endif

/*
 * And lastly files in a compressed directory.
 */

  snprintf(input, sizeof(input), "%s/%s%s.%s/%s", path,
	  MAN, section + len_man, COMPRESSION_EXTENSION, page);
#ifndef HAS_MKSTEMP
  if ( UncompressNamed(man_globals, input, filename) ) {
#else
  if ( UncompressNamed(man_globals, input, filename, file) ) {
#endif
    man_globals->compress = TRUE;
    man_globals->deletetempfile = TRUE;
    snprintf(man_globals->save_file, sizeof(man_globals->save_file),
	     "%s/%s%s.%s/%s", path, CAT, section + len_cat, 
    	     COMPRESSION_EXTENSION, page);
    return(TRUE);
  }
  return(FALSE);
}

/*	Function Name: AddCursor
 *	Description: This function adds the cursor to the window.
 *	Arguments: w - the widget to add the cursor to.
 *                 cursor - the cursor to add to this widget.
 *	Returns: none
 */

void
AddCursor(Widget w, Cursor cursor)
{
  XColor colors[2];
  Arg args[10];
  Cardinal num_args = 0;
  Colormap c_map;

  if (!XtIsRealized(w)) {
    PopupWarning(NULL, "Widget is not realized, no cursor added.\n");
    return;
  }

  XtSetArg( args[num_args], XtNcolormap, &c_map); num_args++;
  XtGetValues( w, args, num_args);

  colors[0].pixel = resources.cursors.fg_color;
  colors[1].pixel = resources.cursors.bg_color;

  XQueryColors (XtDisplay(w), c_map, colors, 2);
  XRecolorCursor(XtDisplay(w), cursor, colors, colors+1);
  XDefineCursor(XtDisplay(w),XtWindow(w),cursor);
}

/*	Function Name: ChangeLabel
 *	Description: This function changes the label field of the
 *                   given widget to the string in str.
 *	Arguments: w - the widget.
 *                 str - the string to change the label to.
 *	Returns: none
 */

void
ChangeLabel(Widget w, char * str)
{
  Arg arglist[3];		/* An argument list. */

  if (w == NULL) return;

  XtSetArg(arglist[0], XtNlabel, str);

/* shouldn't really have to do this. */
  XtSetArg(arglist[1], XtNwidth, 0);
  XtSetArg(arglist[2], XtNheight, 0);

  XtSetValues(w, arglist, (Cardinal) 1);
}

/*
 * In an ideal world this would be part of the XToolkit, and I would not
 * have to do it, but such is life sometimes.  Perhaps in X11R3.
 */

/*	Function Name: PositionCenter
 *	Description: This function positions the given widgets center
 *                   in the following location.
 *	Arguments: widget - the widget widget to postion
 *                 x,y - The location for the center of the widget
 *                 above - number of pixels above center to locate this widget
 *                 left - number of pixels left of center to locate this widget
 *                 h_space, v_space - how close to get to the edges of the
 *                                    parent window.
 *	Returns: none
 *      Note:  This should only be used with a popup widget that has override
 *             redirect set.
 */

void
PositionCenter(Widget widget, int x, int y, int above, int left, int v_space, int h_space)
{
  Arg wargs[2];
  int x_temp,y_temp;		/* location of the new window. */
  int parent_height,parent_width; /* Height and width of the parent widget or
				   the root window if it has no parent. */

  x_temp = x - left - Width(widget) / 2 + BorderWidth(widget);
  y_temp = y - above -  Height(widget) / 2 + BorderWidth(widget);

  parent_height = HeightOfScreen(XtScreen(widget));
  parent_width = WidthOfScreen(XtScreen(widget));

/*
 * Check to make sure that all edges are within the viewable part of the
 * root window, and if not then force them to be.
 */

  if (x_temp < h_space)
    x_temp = v_space;
  if (y_temp < v_space)
    (y_temp = 2);

  if ( y_temp + Height(widget) + v_space > parent_height )
      y_temp = parent_height - Height(widget) - v_space;

  if ( x_temp + Width(widget) + h_space > parent_width )
      x_temp = parent_width - Width(widget) - h_space;

  XtSetArg(wargs[0], XtNx, x_temp);
  XtSetArg(wargs[1], XtNy, y_temp);
  XtSetValues(widget, wargs, 2);
}

/*	Function Name: ParseEntry(entry, path, sect, page)
 *	Description: Parses the manual pages entry filenames.
 *	Arguments: str - the full path name.
 *                 path - the path name.      RETURNED
 *                 sect - the section name.   RETURNED
 *                 page - the page name.      RETURNED
 *	Returns: none.
 */

void
ParseEntry(char *entry, char *path, char *sect, char *page)
{
  char *c, temp[BUFSIZ];

  strcpy(temp, entry);

  c = rindex(temp, '/');
  if (c == NULL)
    PrintError("index failure in ParseEntry.");
  *c++ = '\0';
  if (page != NULL)
    strcpy(page, c);

  c = rindex(temp, '/');
  if (c == NULL)
    PrintError("index failure in ParseEntry.");
  *c++ = '\0';
#if defined(SFORMAT) && defined(SMAN)
  /* sgmltoroff sometimes puts an extra ./ in the path to .so entries */
  if (strcmp(c, ".") == 0) {
      c = rindex(temp, '/');
      if (c == NULL)
	  PrintError("index failure in ParseEntry.");
      *c++ = '\0';
  }
#endif      
#if defined(__OpenBSD__) || defined(__NetBSD__)
  /* Skip machine subdirectory if present */
  if (strcmp(c, MACHINE) == 0) {
      c = rindex(temp, '/');
      if (c == NULL)
	  PrintError("index failure in ParseEntry.");
      *c++ = '\0';
  }
#endif
  if (sect != NULL)
    strcpy(sect, c);

  if (path != NULL)
    strcpy(path, temp);
}

/*      Function Name: GetGlobals
 *      Description: Gets the psuedo globals associated with the
 *                   manpage associated with this widget.
 *      Arguments: w - a widget in the manpage.
 *      Returns: the psuedo globals.
 *      Notes: initial_widget is a globals variable.
 *             manglobals_context is a global variable.
 */

ManpageGlobals *
GetGlobals(Widget w)
{
  Widget temp;
  caddr_t data;

  while ( (temp = XtParent(w)) != initial_widget && (temp != NULL))
    w = temp;

  if (temp == NULL)
    XtAppError(XtWidgetToApplicationContext(w),
	       "Xman: Could not locate widget in tree, exiting");

  if (XFindContext(XtDisplay(w), XtWindow(w),
		   manglobals_context, &data) != XCSUCCESS)
    XtAppError(XtWidgetToApplicationContext(w),
	       "Xman: Could not find global data, exiting");

  return( (ManpageGlobals *) data);
}

/*      Function Name: SaveGlobals
 *      Description: Saves the psuedo globals on the widget passed
 *                   to this function, although GetGlobals assumes that
 *                   the data is associated with the popup child of topBox.
 *      Arguments: w - the widget to associate the data with.
 *                 globals - data to associate with this widget.
 *      Returns: none.
 *      Notes: WIDGET MUST BE REALIZED.
 *             manglobals_context is a global variable.
 */

void
SaveGlobals(Widget w, ManpageGlobals * globals)
{
  if (XSaveContext(XtDisplay(w), XtWindow(w), manglobals_context,
		   (caddr_t) globals) != XCSUCCESS)
    XtAppError(XtWidgetToApplicationContext(w),
	       "Xman: Could not save global data, are you out of memory?");
}

/*      Function Name: RemoveGlobals
 *      Description: Removes the psuedo globals from the widget passed
 *                   to this function.
 *      Arguments: w - the widget to remove the data from.
 *      Returns: none.
 *      Notes: WIDGET MUST BE REALIZED.
 *             manglobals_context is a global variable.
 */

void
RemoveGlobals(Widget w)
{
  if (XDeleteContext(XtDisplay(w), XtWindow(w),
		     manglobals_context) != XCSUCCESS)
    XtAppError(XtWidgetToApplicationContext(w),
	       "Xman: Could not remove global data?");
}
コード例 #4
0
ファイル: xmaze.c プロジェクト: forestbaker/jqian
void screen(int width, int height) {
    int a,r;
    if ((display=XOpenDisplay(NULL)) == NULL) {
        fprintf(stderr,"Could not connect to X server; not using X.\n");
        exit(1);
    }
    scr_ptr = DefaultScreenOfDisplay(display);
    screen_num = DefaultScreen(display);
    for(a=0; a<32; a++) {
        r=XAllocNamedColor(display,DefaultColormap(display,screen_num),\
                           colornames[a],&screen_color,&exact_color);
        if(r==0) {
            fprintf(stderr,"Could not allocate color '%s'.\n",colornames[a]);
            exit(1);
        }
        colors[a]=screen_color.pixel;
        if(a==0) cursorbg=screen_color;
        if(a==1) cursorfg=screen_color;
    }
    totalw=width*mag;
    totalh=height*mag;
    fontwidth=0;
    fontheight=0;
    font=XLoadFont(display,fontname);
    if(font==BadName) {
        fprintf(stderr,"Font %s not found, trying \"fixed\".\n",fontname);
        font=XLoadFont(display,"fixed");
        if(font==BadName) {
            fprintf(stderr,"Fixed font not found.  Giving up.\n");
            exit(1);
        }
    }
    fontinfo=XQueryFont(display,font);
    fontwidth=XTextWidth(fontinfo,"Z",1);
    fontheight=fontinfo->ascent+fontinfo->descent;
    if(statusline) {
        totalh+=fontheight+2;
    }
    main_pixmap=XCreatePixmap(display,DefaultRootWindow(display),\
                              totalw,totalh,DefaultDepth(display,screen_num));

    main_win = XCreateSimpleWindow(display,DefaultRootWindow(display), \
                                   0,0,totalw,totalh,1,colors[1],colors[0]);
    the_GC = XCreateGC(display,main_win,0,0);
    XSetForeground(display,the_GC,0);
    XSetFont(display,the_GC,font);
    XStoreName(display,main_win,"xmaze");
    XMapWindow(display,main_win);
    XSelectInput(display, main_win, ButtonReleaseMask|ButtonPressMask|ExposureMask|VisibilityChangeMask);
    XSetGraphicsExposures(display,the_GC,True);
    XSetForeground(display,the_GC,colors[bg]);
    XSetBackground(display,the_GC,colors[bg]);
    XFillRectangle(display,main_pixmap,the_GC,0,0,totalw,totalh);
    XFillRectangle(display,main_win,the_GC,0,0,totalw,totalh);
    XSetForeground(display,the_GC,colors[fg]);
    // cursor = XCreateFontCursor(display,XC_crosshair);
    // XDefineCursor(display,main_win,cursor);
    //
    // This is why X11 turns off a many budding programmers:
    // Make the cursor a simple red box:
    //
    cursorsource=XCreatePixmap(display,DefaultRootWindow(display),\
                               mag,mag,1);
    cursormask=XCreatePixmap(display,DefaultRootWindow(display),\
                             mag,mag,1);
    XAllocNamedColor(display,DefaultColormap(display,screen_num),\
                     colornames[1],&screen_color,&exact_color);
    cursorbg=screen_color;
    XAllocNamedColor(display,DefaultColormap(display,screen_num),\
                     colornames[0],&screen_color,&exact_color);
    cursorbg=screen_color;
    gc_mask = GCForeground;
    xgcv.foreground = 0;
    gcbg=XCreateGC(display,cursorsource,gc_mask,&xgcv);
    gc_mask = GCForeground;
    xgcv.foreground = 1;
    gcfg=XCreateGC(display,cursorsource,gc_mask,&xgcv);
    XFillRectangle(display,cursormask,gcfg,0,0,mag,mag);
    XFillRectangle(display,cursorsource,gcfg,0,0,mag,mag);
    cursor=XCreatePixmapCursor(display,cursorsource,cursormask,&cursorfg,&cursorbg,mag/2,mag/2);
    XDefineCursor(display,main_win,cursor);
    // See how simple that was?
    wmDeleteMessage = XInternAtom(display, "WM_DELETE_WINDOW", False);
    XSetWMProtocols(display, main_win, &wmDeleteMessage, 1);
    expose();
}
コード例 #5
0
ファイル: x11.c プロジェクト: seanjensengrey/voxel
static void x11_window(void)
{
	if(fullscreen)
	{
		XWindowAttributes attr;
		Window root = DefaultRootWindow(display);
		XGetWindowAttributes(display, root, &attr);

		vid_width = attr.width;
		vid_height = attr.height;

		xwin_attr.override_redirect = True;
		window = XCreateWindow(display, RootWindow(display, xvis->screen),
				0, 0, vid_width, vid_height, 0, xvis->depth, InputOutput,
				xvis->visual, CWBorderPixel | CWColormap | CWEventMask
				| CWOverrideRedirect
				, &xwin_attr);


		XMapRaised(display, window);
//		window = DefaultRootWindow(display);
//		XF86VidModeSetViewPort(display, screen, 0, 0);
//		XWarpPointer(display, None, window, 0, 0, 0, 0,
//				vid_width/2, vid_height/2);
		XGrabKeyboard(display, window, True,
				GrabModeAsync, GrabModeAsync, CurrentTime);
//		XGrabPointer(display, window, True,
//				PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
//				GrabModeAsync, GrabModeAsync, window, None, CurrentTime);
		XDefineCursor(display, window, cursor_none);

	}
	else
	{
		xwin_attr.override_redirect = False;
		window = XCreateWindow(display, RootWindow(display, xvis->screen),
				oldx, oldy, vid_width, vid_height, 0, xvis->depth, InputOutput,
				xvis->visual, CWBorderPixel | CWColormap | CWEventMask
				| CWOverrideRedirect
				, &xwin_attr);

		Atom delwm = XInternAtom(display, "WM_DELETE_WINDOW", False);
		XSetWMProtocols(display, window, &delwm, 1);

		XSetStandardProperties(display, window, "Kittens", "Kitteh", None,
				NULL, 0, NULL);
		XMapRaised(display, window);
	}

	glXMakeCurrent(display, window, glx_context);
	glViewport(0, 0, vid_width, vid_height);
	if(glXIsDirect(display, glx_context))
	{
		printf("OpenGL w/ DRI init ok!\n");
	}
	else
	{
		printf("OpenGL init ok!\n");

	}
}
コード例 #6
0
ファイル: filters.c プロジェクト: yhsesq/yhs
void dgaux_gauy_filter(float sigma){
  int i,j,k,length_gaussian,length_deriv;
  float gaussian[SIZE1],deriv_gaussian[SIZE1];
  matrix dgaux, dgaux_gauy, total_resul, m;
  float rmin,rmax,rng;

  /* Fill in the image with background color */
  for(i=0; i<IMAGE_WIDTH; i++)
	for(j=0; j<IMAGE_HEIGHT; j++)
	    XPutPixel(theXImage_2,i,j,bg);

  /* Clear the drawing window so the image is displayed again */
  XClearArea(XtDisplay(draw_1),XtWindow(draw_2),0,0,0,0,True);

  /* Associate the watch cursor with the main window */
  XDefineCursor(XtDisplay(draw_1), XtWindow(main_window), theCursor);

  /* Flush the request buffer and wait for all events */
  /* and errors to be processed by the server.        */
  XSync(XtDisplay(draw_1), False);
  
  get_gaussian(sigma,gaussian,&length_gaussian);
  fprintf(stderr,"long de gaussian es %i \n",length_gaussian);
  for(i=0;i<=length_gaussian;i++)
  fprintf(stderr,"el gaussian de [%i] es %f \n",i,gaussian[i]);


  get_derigaussian(sigma,deriv_gaussian,&length_deriv);
  fprintf(stderr,"long de deriv gaussian es %i \n",length_deriv);
  for(i=0;i<=length_deriv;i++)
  fprintf(stderr,"el deriv_gaussian de [%i] es %f \n",i,deriv_gaussian[i]);

  for(i=0;i<IMAGE_WIDTH;i++)
    for(j=0;j<IMAGE_HEIGHT;j++)
       m[i][j]= XGetPixel(theXImage_1,i,j);

  /* calculates the convolution of the image with the derivative of a */
  /* gaussian for the rows */
  convo_vectorx(m,deriv_gaussian,length_deriv,&rmax,&rmin,dgaux);

  /* calculate the smoothing of a gaussian(x) in y direction.*/
  convo_vectory(dgaux,gaussian,length_gaussian,&rmax,&rmin,
		dgaux_gauy);

  fprintf(stderr,"Maximum is %f, Minimum is %f\n",rmax,rmin);
  rng=(rmax-rmin);

  for(i=0;i<IMAGE_WIDTH;i++)
	for(j=0;j<IMAGE_HEIGHT;j++)
		total_resul[i][j]=sqrt(pow(dgaux_gauy[i][j],2));
  
  for(i=0;i<IMAGE_WIDTH;i++)
	for(j=0;j<IMAGE_HEIGHT;j++)
	XPutPixel(theXImage_2,i,j,(unsigned long)
	         (((float)(total_resul[i][j]-rmin)/rng)*255.0));
  
  /* Copy image into pixmap */
  XPutImage(XtDisplay(draw_2), thePixmap_2,image_gc_2, theXImage_2,
		 0, 0, 0, 0, theXImage_2->width, theXImage_2->height);
    
  /* Disassociate the watch cursor from the main window */
  XUndefineCursor(XtDisplay(draw_1), XtWindow(main_window));

  /* Clear the drawing window so the image is displayed again */
  XClearArea(XtDisplay(draw_2),XtWindow(draw_2),0,0,0,0,True);

}
コード例 #7
0
static void install_grabs( void )
{
	int res;
	int fevent;

	assert( x11display.dpy && x11display.win );

	if( !x11display.features.wmStateFullscreen )
	{
		res = XGrabKeyboard( x11display.dpy, x11display.win, False, GrabModeAsync, GrabModeAsync, CurrentTime );
		if( res != GrabSuccess )
		{
			Com_Printf( "Warning: XGrabKeyboard failed\n" );
			return;
		}
	}

	XDefineCursor( x11display.dpy, x11display.win, CreateNullCursor( x11display.dpy, x11display.win ) );

	res = XGrabPointer( x11display.dpy, x11display.win, True, 0, GrabModeAsync, GrabModeAsync, x11display.win, None, CurrentTime );
	if( res != GrabSuccess )
	{
		// TODO: Find a solution to Pointer Grabs at focus changes, which sometimes result
		// in Grabbing Errors. Like switches from Windowed/Fullscreen to Hidden State.
		//Com_Printf( "Warning: XGrabPointer failed\n" );
		XUngrabKeyboard( x11display.dpy, CurrentTime );
		XUndefineCursor( x11display.dpy, x11display.win );
		return;
	}

	if( in_dgamouse->integer )
	{
		int MajorVersion, MinorVersion;

		if( XF86DGAQueryVersion( x11display.dpy, &MajorVersion, &MinorVersion ) )
		{
			XF86DGADirectVideo( x11display.dpy, x11display.scr, XF86DGADirectMouse );
			XWarpPointer( x11display.dpy, None, x11display.win, 0, 0, 0, 0,
				x11display.win_width/2, x11display.win_height/2 );
			dgamouse = qtrue;
		}
		else
		{
			// unable to query, probalby not supported
			Com_Printf( "Failed to detect XF86DGA Mouse\n" );
			Cvar_Set( "in_dgamouse", "0" );
			dgamouse = qfalse;
		}
	}
	else
	{
		XWarpPointer( x11display.dpy, None, x11display.win, 0, 0, 0, 0,
			x11display.win_width/2, x11display.win_height/2 );
	}

	ignore_one = qtrue; // first mouse update after install_grabs is ignored
	mx = my = 0;
	mouse_active = qtrue;

	in_dgamouse->modified = qfalse;

	input_active = qtrue;

	// init X Input method, needed by Xutf8LookupString
	x11display.im = XOpenIM( x11display.dpy, NULL, NULL, NULL );
	x11display.ic = XCreateIC( x11display.im,
		XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
		XNClientWindow, x11display.win,
		NULL );
	if ( x11display.ic )
	{
		XGetICValues( x11display.ic, XNFilterEvents, &fevent, NULL );
		XSelectInput( x11display.dpy, x11display.win, fevent | x11display.wa.event_mask );
	}
}
コード例 #8
0
ファイル: tic.c プロジェクト: BIC-MNI/xdisp
/*-------------------------- TIC ---------------------------------*/
int TIC()
{
  int 	i, j, im, org_image; 
  char  tmp_name[40], tmp_cmd[80];
  float rw_loc;
  FILE	*out;    
    
  /* check that an roi is defined */
  if (roi_present != 1) {
    fprintf(stderr,"An ROI must be drawn before calculating its time course.\n");
    return;
  }

  /* open output file */
  tmpnam(tmp_name);
  if(!(out = fopen(tmp_name,"w"))){ 
    fprintf(stderr,"Unable to open temporary file\n");
    return;
  }

  /* define new cursors */
  XDefineCursor(theDisp,mainW,waitCursor);
  XDefineCursor(theDisp,cmdW,waitCursor);
  XFlush(theDisp);

  /* save current image position */
  org_image = image_number;
    
  /* cycle through images and dump results to file */
  for (im=0; im<slider_length[current_dim]; im++) {
    fprintf(stderr,"Processing image %d\r",im+1);
    image_increment = im - slider_image[current_dim];
    New_Image();
    draw_roi(roi_x1,roi_y1,roi_x2,roi_y2);
    roi_stats(roi_x1*(Width-1)/(zWidth-1),
	      roi_y1*(Height-1)/(zHeight-1),
	      roi_x2*(Width-1)/(zWidth-1),
	      roi_y2*(Height-1)/(zHeight-1),1);
    if (file_format==MINC_FORMAT && 
	RW_valid &&
	minc_volume_info.step[current_dim]!=0 ) {
      rw_loc = minc_volume_info.start[current_dim] + 
	(float) slider_image[current_dim] * 
	minc_volume_info.step[current_dim];
      fprintf(out,"%f %f %f \n",rw_loc,tic_mean,tic_std);
    }
    else {
      fprintf(out,"%d  %f %f\n",im+1,tic_mean,tic_std);
    }
  }

  /* display original image */
  image_increment = org_image - image_number;
  New_Image();
  draw_roi(roi_x1,roi_y1,roi_x2,roi_y2);
    
  /* print plot commands */
  fprintf(out,"@s0 type xy \n");
  fprintf(out,"@s0 symbol 2 \n");
  fprintf(out,"@s0 symbol fill 1 \n");
  if (file_format==MINC_FORMAT && 
      RW_valid &&
      minc_volume_info.step[current_dim]!=0 ) {
    fprintf(out,"@xaxis label \"%s (%s)\"\n", 
	    minc_volume_info.dimension_names[current_dim],
	    minc_volume_info.dimension_units[current_dim]);
  }
  else if (file_format==MINC_FORMAT) {
    fprintf(out,"@xaxis label \"Frame (%s)\"\n", 
	    minc_volume_info.dimension_names[current_dim]);
  }
  else {
    fprintf(out,"@xaxis label \"Image Number\"\n");
  }
  fprintf(out,"@yaxis label \"ROI Mean\"\n");
  fprintf(out,"@title \"%s\"\n",basfname);
  fprintf(out,"@frame fill on\n");
  fprintf(out,"@frame background color 7\n");

  /* close file */
  fclose(out);
  fprintf(stderr,"                                              \r");

  /* issue shell commands */
  if (GRACE) {
    sprintf(tmp_cmd,"cat %s | xmgrace -pipe &\n",tmp_name); 
  }
  else {
    sprintf(tmp_cmd,"cat %s | xmgr -xy -source stdin &\n",tmp_name); 
  }
  system (tmp_cmd); 
  sprintf(tmp_cmd,"rm %s &\n",tmp_name); 
  system (tmp_cmd); 
    
  /* define new cursors */
  XDefineCursor(theDisp,mainW,mainCursor);
  XDefineCursor(theDisp,cmdW,cmdCursor);
  XFlush(theDisp);
}
コード例 #9
0
ファイル: MainNoGUI.cpp プロジェクト: hminth/dolphin
	void MainLoop() override
	{
		bool fullscreen = SConfig::GetInstance().m_LocalCoreStartupParameter.bFullscreen;

		if (fullscreen)
		{
			X11Utils::ToggleFullscreen(dpy, win);
#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::ToggleFullscreen(dpy, win);
#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;
				case ClientMessage:
					if ((unsigned long) event.xclient.data.l[0] == XInternAtom(dpy, "WM_DELETE_WINDOW", False))
						running = false;
					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);
		}
	}
コード例 #10
0
ファイル: x11keyfaker.cpp プロジェクト: Fale/qtmoko
void X11KeyFaker::connect()
{
    // Open the display.
    dpy = XOpenDisplay(displayName.toLatin1().data());
    if (!dpy) {
        // Try again in a few milliseconds.  Xnest may not be alive yet.
        // Give up after 10 seconds.
        if (++retryCount < 50)
            QTimer::singleShot(200, this, SLOT(connect()));
        else
            QTimer::singleShot(0, this, SIGNAL(couldNotConnect()));
        return;
    }

    // Query the XTest extension, which we need to fake the key events.
    int event_base, error_base, major, minor;
    if (!XTestQueryExtension
            (dpy, &event_base, &error_base, &major, &minor)) {
        XCloseDisplay(dpy);
        dpy = 0;
        QTimer::singleShot(0, this, SIGNAL(couldNotConnect()));
        return;
    }

    // Modify the Xnest's keyboard mappings to add Qtopia's special keysyms.
    int min_keycode = 1, max_keycode = 255;
    XDisplayKeycodes(dpy, &min_keycode, &max_keycode);
    bool ok = true;
    for (KeySym key = QTOPIAXK_Max; key >= QTOPIAXK_Min; --key) {
        // This is an extension keysym, not part of the standard X11 set.
        if (!allocateSpecialKeysym(dpy, min_keycode, max_keycode, key)) {
            ok = false;
            break;
        }
    }
    static const KeySym specials[] = {
        XF86XK_Back,		    // Qt::Key_Back
        XF86XK_AudioLowerVolume,    // Qt::Key_VolumeUp
        XF86XK_AudioRaiseVolume,    // Qt::Key_VolumeDown
        XK_F28,			    // Qt::Key_F28
        NoSymbol
    };
    int index = 0;
    while (ok && specials[index] != NoSymbol) {
        // This is a standard X11/XFree86 keysym that Qtopia uses,
        // but it may not be on the user's physical keyboard.
        if (!allocateSpecialKeysym
                (dpy, min_keycode, max_keycode, specials[index]))
            ok = false;
        ++index;
    }
    if (!ok)
        qWarning() << "There are insufficient spare X11 keycodes to allocate the special Qtopia keys";

    // Change the root cursor to something more reasonable than "X".
    Cursor cursor = XCreateFontCursor(dpy, XC_left_ptr);
    XDefineCursor(dpy, RootWindow(dpy, DefaultScreen(dpy)), cursor);

    // Look up the shift keys.
    shiftKeycode = XKeysymToKeycode(dpy, XK_Shift_L);
    if (shiftKeycode == NoSymbol)
        shiftKeycode = XKeysymToKeycode(dpy, XK_Shift_R);
    modeSwitchKeycode = XKeysymToKeycode(dpy, XK_Mode_switch);

    // Make sure all of the above changes are flushed.
    XFlush(dpy);

    // Set up event handling for the display.
    QSocketNotifier *notifier = new QSocketNotifier
    (ConnectionNumber(dpy), QSocketNotifier::Read, this);
    QObject::connect(notifier, SIGNAL(activated(int)), this, SLOT(readyRead()));

    // Make sure the file descriptor is not inherited across exec's.
    fcntl(ConnectionNumber(dpy), F_SETFD, 1);

    // Notify interested parties that we are now connected to the X display.
    QTimer::singleShot(0, this, SIGNAL(connected()));
}
コード例 #11
0
ファイル: x_wglbtn.c プロジェクト: armnlib/xrec
int x_wglbtn(int bouton)
{
   wglfshlb();

   XDefineCursor(wglDisp,wglWin,croix);
   while (True)
      {
      XtAppNextEvent(SuperWidget.contexte, &wglEvent);
      switch(wglEvent.type) 
         {
         case ButtonPress:
         if (wglEvent.xbutton.window != wglWin)
	    {
	    XDefineCursor(wglDisp,wglWin,None);
	    XBell(wglDisp, 0);
	    }
	 else
	    {
	    XDefineCursor(wglDisp,wglWin,None);
	    switch(bouton)
	       {
	       case BGAUCH:
	       switch(wglEvent.xbutton.button)
		  {
		  case Button1:
		  return True;
		  
		  default:
		  return False;
		  }
	       
	       case BMLIEU:
	       switch(wglEvent.xbutton.button)
		  {
		  case Button2:
		  return True;
		  
		  default:
		  return False;
		  }
	       
	       case BDROIT:
	       switch(wglEvent.xbutton.button)
		  {
		  case Button3:
		  return True;
		  
		  default:
		  return False;
		  }
	       
	       case BTOUS:
	       switch(wglEvent.xbutton.button)
		  {
		  case Button1:
		  case Button2:
		  case Button3:
		  return True;
		  
		  default:
		  return False;
		  }
	       }
            }
         
         default:
         XtDispatchEvent(&wglEvent);
         }
      }
   
   XDefineCursor(wglDisp,wglWin,None);
   }
コード例 #12
0
static bool xdpy_set_system_mouse_cursor(ALLEGRO_DISPLAY *display,
   ALLEGRO_SYSTEM_MOUSE_CURSOR cursor_id)
{
   ALLEGRO_DISPLAY_XGLX *glx = (ALLEGRO_DISPLAY_XGLX *)display;
   ALLEGRO_SYSTEM_XGLX *system = (ALLEGRO_SYSTEM_XGLX *)al_get_system_driver();
   Display *xdisplay = system->x11display;
   Window xwindow = glx->window;
   unsigned int cursor_shape;

   switch (cursor_id) {
      case ALLEGRO_SYSTEM_MOUSE_CURSOR_DEFAULT:
      case ALLEGRO_SYSTEM_MOUSE_CURSOR_ARROW:
      case ALLEGRO_SYSTEM_MOUSE_CURSOR_PROGRESS:
         cursor_shape = XC_left_ptr;
         break;
      case ALLEGRO_SYSTEM_MOUSE_CURSOR_BUSY:
         cursor_shape = XC_watch;
         break;
      case ALLEGRO_SYSTEM_MOUSE_CURSOR_QUESTION:
         cursor_shape = XC_question_arrow;
         break;
      case ALLEGRO_SYSTEM_MOUSE_CURSOR_EDIT:
         cursor_shape = XC_xterm;
         break;
      case ALLEGRO_SYSTEM_MOUSE_CURSOR_MOVE:
         cursor_shape = XC_fleur;
         break;
      case ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_N:
         cursor_shape = XC_top_side;
         break;
      case ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_S:
         cursor_shape = XC_bottom_side;
         break;
      case ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_E:
         cursor_shape = XC_right_side;
         break;
      case ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_W:
         cursor_shape = XC_left_side;
         break;
      case ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_NE:
         cursor_shape = XC_top_right_corner;
         break;
      case ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_SW:
         cursor_shape = XC_bottom_left_corner;
         break;
      case ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_NW:
         cursor_shape = XC_top_left_corner;
         break;
      case ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_SE:
         cursor_shape = XC_bottom_right_corner;
         break;
      case ALLEGRO_SYSTEM_MOUSE_CURSOR_PRECISION:
         cursor_shape = XC_crosshair;
         break;
      case ALLEGRO_SYSTEM_MOUSE_CURSOR_LINK:
         cursor_shape = XC_hand2;
         break;
      case ALLEGRO_SYSTEM_MOUSE_CURSOR_ALT_SELECT:
         cursor_shape = XC_hand1;
         break;
      case ALLEGRO_SYSTEM_MOUSE_CURSOR_UNAVAILABLE:
         cursor_shape = XC_X_cursor;
         break;
      default:
         return false;
   }

   _al_mutex_lock(&system->lock);

   glx->current_cursor = XCreateFontCursor(xdisplay, cursor_shape);
   /* XXX: leak? */

   if (!glx->cursor_hidden) {
      XDefineCursor(xdisplay, xwindow, glx->current_cursor);
   }

   _al_mutex_unlock(&system->lock);

   return true;
}
コード例 #13
0
ファイル: freeglut_cursor.c プロジェクト: acplus/peptalk
/*
 * Set the cursor image to be used for the current window
 */
void fgSetCursor ( SFG_Window *window, int cursorID )
{
#if TARGET_HOST_UNIX_X11
    {
        Cursor cursor;
        /*
         * XXX FULL_CROSSHAIR demotes to plain CROSSHAIR. Old GLUT allows
         * for this, but if there is a system that easily supports a full-
         * window (or full-screen) crosshair, we might consider it.
         */
        int cursorIDToUse =
            ( cursorID == GLUT_CURSOR_FULL_CROSSHAIR ) ? GLUT_CURSOR_CROSSHAIR : cursorID;

        if( ( cursorIDToUse >= 0 ) &&
            ( cursorIDToUse < sizeof( cursorCache ) / sizeof( cursorCache[0] ) ) ) {
            cursorCacheEntry *entry = &cursorCache[ cursorIDToUse ];
            if( entry->cachedCursor == None ) {
                entry->cachedCursor =
                    XCreateFontCursor( fgDisplay.Display, entry->cursorShape );
            }
            cursor = entry->cachedCursor;
        } else {
            switch( cursorIDToUse )
            {
            case GLUT_CURSOR_NONE:
                cursor = getEmptyCursor( );
                break;

            case GLUT_CURSOR_INHERIT:
                cursor = None;
                break;

            default:
                fgError( "Unknown cursor type: %d", cursorIDToUse );
                return;
            }
        }

        if ( ( cursorIDToUse != GLUT_CURSOR_NONE ) && ( cursor == None ) ) {
            fgError( "Failed to create cursor" );
        }
        XDefineCursor( fgDisplay.Display,
                       window->Window.Handle, cursor );
    }

#elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE

    /*
     * This is a temporary solution only...
     */
    /* Set the cursor AND change it for this window class. */
#       define MAP_CURSOR(a,b)                                   \
        case a:                                                  \
            SetCursor( LoadCursor( NULL, b ) );                  \
            SetClassLong( window->Window.Handle,                 \
                          GCL_HCURSOR,                           \
                          ( LONG )LoadCursor( NULL, b ) );       \
        break;

    /* Nuke the cursor AND change it for this window class. */
#       define ZAP_CURSOR(a,b)                                   \
        case a:                                                  \
            SetCursor( NULL );                                   \
            SetClassLong( window->Window.Handle,                 \
                          GCL_HCURSOR, ( LONG )NULL );           \
        break;

    switch( cursorID )
    {
        MAP_CURSOR( GLUT_CURSOR_RIGHT_ARROW,         IDC_ARROW     );
        MAP_CURSOR( GLUT_CURSOR_LEFT_ARROW,          IDC_ARROW     );
        MAP_CURSOR( GLUT_CURSOR_INFO,                IDC_HELP      );
        MAP_CURSOR( GLUT_CURSOR_DESTROY,             IDC_CROSS     );
        MAP_CURSOR( GLUT_CURSOR_HELP,                IDC_HELP      );
        MAP_CURSOR( GLUT_CURSOR_CYCLE,               IDC_SIZEALL   );
        MAP_CURSOR( GLUT_CURSOR_SPRAY,               IDC_CROSS     );
        MAP_CURSOR( GLUT_CURSOR_WAIT,                IDC_WAIT      );
        MAP_CURSOR( GLUT_CURSOR_TEXT,                IDC_IBEAM     );
        MAP_CURSOR( GLUT_CURSOR_CROSSHAIR,           IDC_CROSS     );
        MAP_CURSOR( GLUT_CURSOR_UP_DOWN,             IDC_SIZENS    );
        MAP_CURSOR( GLUT_CURSOR_LEFT_RIGHT,          IDC_SIZEWE    );
        MAP_CURSOR( GLUT_CURSOR_TOP_SIDE,            IDC_ARROW     ); /* XXX ToDo */
        MAP_CURSOR( GLUT_CURSOR_BOTTOM_SIDE,         IDC_ARROW     ); /* XXX ToDo */
        MAP_CURSOR( GLUT_CURSOR_LEFT_SIDE,           IDC_ARROW     ); /* XXX ToDo */
        MAP_CURSOR( GLUT_CURSOR_RIGHT_SIDE,          IDC_ARROW     ); /* XXX ToDo */
        MAP_CURSOR( GLUT_CURSOR_TOP_LEFT_CORNER,     IDC_SIZENWSE  );
        MAP_CURSOR( GLUT_CURSOR_TOP_RIGHT_CORNER,    IDC_SIZENESW  );
        MAP_CURSOR( GLUT_CURSOR_BOTTOM_RIGHT_CORNER, IDC_SIZENWSE  );
        MAP_CURSOR( GLUT_CURSOR_BOTTOM_LEFT_CORNER,  IDC_SIZENESW  );
        MAP_CURSOR( GLUT_CURSOR_INHERIT,             IDC_ARROW     ); /* XXX ToDo */
        ZAP_CURSOR( GLUT_CURSOR_NONE,                NULL          );
        MAP_CURSOR( GLUT_CURSOR_FULL_CROSSHAIR,      IDC_CROSS     ); /* XXX ToDo */

    default:
        fgError( "Unknown cursor type: %d", cursorID );
        break;
    }
#endif

    window->State.Cursor = cursorID;
}
コード例 #14
0
ファイル: scrollbar.c プロジェクト: idunham/dtextra
void
ScrollBarOn (XtermWidget xw, int init, int doalloc)
{
#ifdef MOTIF
    Cursor arrowCursor;
#endif /* MOTIF */
    register TScreen *screen = &xw->screen;
    register int i, j, k;

    if(screen->fullVwin.scrollbar)
        return;

    if (init) {			/* then create it only */
        if (screen->scrollWidget) return;

        /* make it a dummy size and resize later */
        if ((screen->scrollWidget = CreateScrollBar (xw, -1, -1, 5))
                == NULL) {
            Bell(XkbBI_MinorError,0);
            return;
        }

        return;

    }

    if (!screen->scrollWidget) {
        Bell (XkbBI_MinorError,0);
        Bell (XkbBI_MinorError,0);
        return;
    }

    if (doalloc && screen->allbuf) {
        /* FIXME: this is not integrated well with Allocate */
        if((screen->allbuf =
                    (ScrnBuf) realloc((char *) screen->visbuf,
                                      (unsigned) MAX_PTRS*(screen->max_row + 2 +
                                              screen->savelines) *
                                      sizeof(char *)))
                == NULL)
            Error (ERROR_SBRALLOC);
        screen->visbuf = &screen->allbuf[MAX_PTRS * screen->savelines];
        memmove( (char *)screen->visbuf, (char *)screen->allbuf,
                 MAX_PTRS * (screen->max_row + 2) * sizeof (char *));
        for (i = k = 0; i < screen->savelines; i++) {
            k += BUF_HEAD;
            for (j = BUF_HEAD; j < MAX_PTRS; j++) {
                if((screen->allbuf[k++] =
                            (Char *)calloc((unsigned) screen->max_col + 1, sizeof(Char))) ==
                        NULL)
                    Error (ERROR_SBRALLOC2);
            }
        }
    }

    ResizeScrollBar (screen);
    XtRealizeWidget (screen->scrollWidget);
#ifdef MOTIF
    /* define pointer cursor for it */
    arrowCursor = XCreateFontCursor(XtDisplay(screen->scrollWidget), XC_left_ptr);
    XDefineCursor(XtDisplay(screen->scrollWidget), XtWindow(screen->scrollWidget), arrowCursor);
    XFreeCursor(XtDisplay(screen->scrollWidget), arrowCursor);
#endif /* MOTIF */
    screen->fullVwin.scrollbar = screen->scrollWidget->core.width +
                                 screen->scrollWidget->core.border_width;

    ScrollBarDrawThumb(screen->scrollWidget);
    DoResizeScreen (xw);

#ifdef SCROLLBAR_RIGHT
    /*
     * Adjust the scrollbar position if we're asked to turn on scrollbars
     * for the first time after the xterm is already running.  That makes
     * the window grow after we've initially configured the scrollbar's
     * position.  (There must be a better way).
     */
    if (term->misc.useRight
            && screen->fullVwin.fullwidth < term->core.width)
        XtVaSetValues(screen->scrollWidget,
                      XtNx, screen->fullVwin.fullwidth - screen->scrollWidget->core.border_width,
                      NULL);
#endif

    XtMapWidget(screen->scrollWidget);
    update_scrollbar ();
    if (screen->visbuf) {
        XClearWindow (screen->display, XtWindow (term));
        Redraw ();
    }
}
コード例 #15
0
ファイル: filters.c プロジェクト: yhsesq/yhs
/* pow(gradient,2) = pow(differencex,2)+pow(differencey,2) */
void gradient_filter(){
  int i,j,first;
  matrix m; 
  float mask[2]={1,-1};
  matrix dx, dy, gradient; 
  float rmax, rmin, rng;

  /* Fill in the image with background color */
  for(i=0; i<IMAGE_WIDTH; i++)
    for(j=0; j<IMAGE_HEIGHT; j++)
      XPutPixel(theXImage_2,i,j,bg);

  /* Clear the drawing window so the image is displayed again */
  XClearArea(XtDisplay(draw_1),XtWindow(draw_2),0,0,0,0,True);

  /* Associate the watch cursor with the main window */
  XDefineCursor(XtDisplay(draw_1), XtWindow(main_window), theCursor);

  /* Flush the request buffer and wait for all events */
  /* and errors to be processed by the server.        */
  XSync(XtDisplay(draw_1), False);

  /* Storing the image in a matrix */
  for(i=0;i<IMAGE_WIDTH;i++)
    for(j=0;j<IMAGE_HEIGHT;j++)
       m[i][j]= XGetPixel(theXImage_1,i,j);

  /* Taking differences between the values of horizontally adjacent pixels */
  convo_vectorx(m, mask, 1, &rmax, &rmin, dx);

  /* Taking differences between the values of vertical adjacent pixels */
  convo_vectory(m, mask, 1, &rmax, &rmin, dy);

  first=1;
  for(i=0;i<IMAGE_WIDTH;i++)
    for(j=0;j<IMAGE_HEIGHT;j++){
	gradient[i][j] = sqrt(pow(dx[i][j],2)+pow(dy[i][j],2));
	if (first==1){ rmax = gradient[i][j];
		       rmin = rmax;
		       first = 2;}
	if (gradient[i][j]<rmin) rmin = gradient[i][j];
	if (gradient[i][j]>rmax) rmax = gradient[i][j];
  }

  rng = (rmax-rmin);

  for(i=0;i<512;i++)
    for(j=0;j<511;j++)
      XPutPixel(theXImage_2,i,j,(unsigned long)
		(((float)(gradient[i][j]-rmin)/rng)*255.0));

  /* Copy image into pixmap */
  XPutImage(XtDisplay(draw_2), thePixmap_2, image_gc_2, theXImage_2,
		 0, 0, 0, 0, theXImage_2->width, theXImage_2->height);

  /* Disassociate the watch cursor from the main window */
  XUndefineCursor(XtDisplay(draw_1), XtWindow(main_window));

  /* Clear the drawing window so the image is displayed again */
  XClearArea(XtDisplay(draw_2),XtWindow(draw_2),0,0,0,0,True);
}		
コード例 #16
0
ファイル: x11_window.cpp プロジェクト: xubingyue/ClanLib
	void X11Window::show_system_cursor()
	{
		XDefineCursor(handle.display, handle.window, system_cursor);
	}
コード例 #17
0
ファイル: filters.c プロジェクト: yhsesq/yhs
void d2gaussian_filter(float sigma){
  int i,j,length_d2gaussian,lon,start;
  float rmax, rmin, rng, value, mask_d2gaussian[SIZE2][SIZE2];
  float d2gaussian[SIZE1];
  matrix m,resul,d2erix,d2eriy;

  /* Fill in the image with background color */
    for(i=0; i<IMAGE_WIDTH; i++)
	for(j=0; j<IMAGE_HEIGHT; j++)
	    XPutPixel(theXImage_2,i,j,bg);

  /* Clear the drawing window so the image is displayed again */
  XClearArea(XtDisplay(draw_1),XtWindow(draw_2),0,0,0,0,True);

  /* Associate the watch cursor with the main window */
  XDefineCursor(XtDisplay(draw_1), XtWindow(main_window), theCursor);

  /* Flush the request buffer and wait for all events */
  /* and errors to be processed by the server.        */
  XSync(XtDisplay(draw_1), False);

  /* Storing the matrix we want to process in m */
  for(i=0;i<IMAGE_WIDTH;i++)
    for(j=0;j<IMAGE_HEIGHT;j++)
       m[i][j]= XGetPixel(theXImage_1,i,j);

  get_2derigaussian(sigma, d2gaussian, &length_d2gaussian);
  
  fprintf(stderr,"la long es %i \n",length_d2gaussian);

  /* Only the values higher than 0.01 are desirable */
  start=0;
  value=pow(d2gaussian[0],2);
  fprintf(stderr,"el top es %f\n",top);

  while (value<0.01*pow(top,2)){
        start += 1;
  	value = pow(d2gaussian[start],2);
  }
  
     
  for(i=start;i<=length_d2gaussian-start;i++)
     for(j=start;j<=length_d2gaussian-start;j++){
	   mask_d2gaussian[i-start][j-start]= d2gaussian[i]*d2gaussian[j];	  
           fprintf(stderr,"la %i,%i es %f, \n",i-start,j-start,
		mask_d2gaussian[i-start][j-start]);
	 }

  length_d2gaussian = length_d2gaussian - (2*start);
  fprintf(stderr,"la long es %i \n",length_d2gaussian);
  convolution(m,mask_d2gaussian,length_d2gaussian,&rmax,&rmin,resul);


  /* convo_vectorx(m,d2gaussian,length_d2gaussian,&rmax,&rmin,d2erix);
  convo_vectory(m,d2gaussian,length_d2gaussian,&rmax,&rmin,d2eriy);
  for(i=0;i<IMAGE_WIDTH;i++)  
    for(j=0;j<IMAGE_HEIGHT;j++){
	resul[i][j]=sqrt(pow(d2erix[i][j],2)+pow(d2eriy[i][j],2));
	if (i==0 && j==0){rmax=resul[0][0];
			  rmin=rmax;}
        if (resul[i][j]>rmax) rmax=resul[i][j];
        if (resul[i][j]<rmin) rmin=resul[i][j];
  }
  rng=(rmax-rmin);  
  for(i=0;i<IMAGE_WIDTH;i++)
    for(j=0;j<IMAGE_HEIGHT;j++)
        XPutPixel(theXImage_2,i,j,(unsigned long)
		 (((float)(resul[i][j]-rmin)/rng)*255.0));*/
  
 
  rng = (float) (rmax - rmin);
  lon = length_d2gaussian/2;
  
  /* Now compute the convolution, scaling. */
  for (i=lon; i<IMAGE_WIDTH-lon; i++)
   for (j=lon; j<IMAGE_HEIGHT-lon; j++)
        XPutPixel(theXImage_2,i,j,
		(unsigned long) (((float)(resul[i][j]-rmin)/rng)*255.0));
  
  /* Copy image into pixmap. */
  XPutImage(XtDisplay(draw_2), thePixmap_2,image_gc_2, theXImage_2,
	0, 0, 0, 0, theXImage_2->width, theXImage_2->height);
  
 
  /* Disassociate the watch cursor from the main window */
  XUndefineCursor(XtDisplay(draw_1), XtWindow(main_window));

  /* Clear the drawing window so the image is displayed again */
  XClearArea(XtDisplay(draw_2),XtWindow(draw_2),0,0,0,0,True);
}
コード例 #18
0
ファイル: x11_window.cpp プロジェクト: xubingyue/ClanLib
	void X11Window::hide_system_cursor()
	{
		XDefineCursor(handle.display, handle.window, hidden_cursor);
	}
コード例 #19
0
ファイル: filters.c プロジェクト: yhsesq/yhs
/* Gradient_x_y = sqrt(pow(gaussian_x,2)+pow(gaussian_y,2) */
void gradient_x_y_filter(float sigma){
  int i,j,k,length_deriv;
  float deriv_gaussian[SIZE1];
  matrix dgaux, dgauy, gradient_x_y, m;
  float rmin,rmax,rng;

  /* Fill in the image with background color */
  for(i=0; i<IMAGE_WIDTH; i++)
	for(j=0; j<IMAGE_HEIGHT; j++)
	    XPutPixel(theXImage_2,i,j,bg);

  /* Clear the drawing window so the image is displayed again */
  XClearArea(XtDisplay(draw_1),XtWindow(draw_2),0,0,0,0,True);

  /* Associate the watch cursor with the main window */
  XDefineCursor(XtDisplay(draw_1), XtWindow(main_window), theCursor);

  /* Flush the request buffer and wait for all events */
  /* and errors to be processed by the server.        */
  XSync(XtDisplay(draw_1), False);
  
  get_derigaussian(sigma,deriv_gaussian,&length_deriv);
  
  for(i=0;i<IMAGE_WIDTH;i++)
    for(j=0;j<IMAGE_HEIGHT;j++)
       m[i][j]= XGetPixel(theXImage_1,i,j);

  /* Apply convolution with derivative of a gaussian to the rows */
  convo_vectorx(m,deriv_gaussian,length_deriv,&rmax,&rmin,dgaux);

  /* Apply convolution with derivative of a gaussian to the columns */
  convo_vectory(m,deriv_gaussian,length_deriv,&rmax,&rmin,dgauy);
  
  
  for(i=0;i<IMAGE_WIDTH;i++)  
    for(j=0;j<IMAGE_HEIGHT;j++){
	gradient_x_y[i][j]=sqrt(pow(dgaux[i][j],2)+
				  pow(dgauy[i][j],2));
	if (i==0 && j==0){rmax=gradient_x_y[0][0];
			  rmin=rmax;}
        if (gradient_x_y[i][j]>rmax) rmax=gradient_x_y[i][j];
        if (gradient_x_y[i][j]<rmin) rmin=gradient_x_y[i][j];
  }
  
  rng=(rmax-rmin);  

  for(i=0;i<IMAGE_WIDTH;i++)
    for(j=0;j<IMAGE_HEIGHT;j++)
        XPutPixel(theXImage_2,i,j,(unsigned long)
		 (((float)(gradient_x_y[i][j]-rmin)/rng)*255.0));
  
  /* Copy image into pixmap */
  XPutImage(XtDisplay(draw_2), thePixmap_2,image_gc_2, theXImage_2,
		 0, 0, 0, 0, theXImage_2->width, theXImage_2->height);
  
  
  /* Disassociate the watch cursor from the main window */
  XUndefineCursor(XtDisplay(draw_1), XtWindow(main_window));

  /* Clear the drawing window so the image is displayed again */
  XClearArea(XtDisplay(draw_2),XtWindow(draw_2),0,0,0,0,True);

}
コード例 #20
0
ファイル: WindowImplX11.cpp プロジェクト: AwkwardDev/MangosFX
////////////////////////////////////////////////////////////
/// /see WindowImpl::ShowMouseCursor
////////////////////////////////////////////////////////////
void WindowImplX11::ShowMouseCursor(bool Show)
{
    XDefineCursor(ourDisplay, myWindow, Show ? None : myHiddenCursor);
    XFlush(ourDisplay);
}
コード例 #21
0
ファイル: xlib_events.c プロジェクト: BehaviorEnterprises/Fex
void keypress(XEvent *ev) {
	XKeyEvent *e = &ev->xkey;
	KeySym sym = XkbKeycodeToKeysym(dpy, (KeyCode)e->keycode, 0, 0);
	int mod = ((e->state & ~Mod2Mask) & ~LockMask);
	if (mod == (ControlMask | ShiftMask)) {
		if (sym == XK_q) {
			spect->fex = 0;
			running = False;
		}
		if (sym == XK_j || sym == XK_Down) threshold(-0.05);
		else if (sym == XK_k || sym == XK_Up) threshold(0.05);
		else if (sym == XK_h || sym == XK_Left) sp_floor(-0.05);
		else if (sym == XK_l || sym == XK_Right) sp_floor(0.05);
		else if (sym == XK_p) play(0.1666);
	}
	else if (mod == (Mod1Mask | ShiftMask)) {
		if (sym == XK_p) play(0.08333);
	}
	else if (mod == ControlMask) {
		if (sym == XK_q) running = False;
		else if (sym == XK_f) series_export();
		else if (sym == XK_s) screenshot();
		else if (sym == XK_i) img_draw();
		else if (sym == XK_j || sym == XK_Down) zoom(-0.025);
		else if (sym == XK_k || sym == XK_Up) zoom(0.025);
		else if (sym == XK_h || sym == XK_Left) return;
		else if (sym == XK_l || sym == XK_Right) return;
		else if (sym == XK_p) play(0.33);
	}
	else if (mod == Mod1Mask) {
		if (sym == XK_j || sym == XK_Down) eraser_cursor(-1,-1);
		else if (sym == XK_k || sym == XK_Up) eraser_cursor(1,1);
		else if (sym == XK_h || sym == XK_Left) eraser_cursor(-1,1);
		else if (sym == XK_l || sym == XK_Right) eraser_cursor(1,-1);
		else if (sym == XK_p) play(0.25);
	}
	else if (mod == ShiftMask) {
		if (sym == XK_j || sym == XK_Down) pt_line(-0.2,0);
		else if (sym == XK_k || sym == XK_Up) pt_line(0.2,0);
		else if (sym == XK_h || sym == XK_Left) pt_line(0,-0.2);
		else if (sym == XK_l || sym == XK_Right) pt_line(0,0.2);
		else if (sym == XK_p) play(0.5);
	}
	else if (sym == XK_j || sym == XK_Down) move(0,0.02);
	else if (sym == XK_k || sym == XK_Up) move(0,-0.02);
	else if (sym == XK_h || sym == XK_Left) move(0.02,0);
	else if (sym == XK_l || sym == XK_Right) move(-0.02,0);
	else if (sym == XK_F1) {
		if (fork() == 0) {
			close(ConnectionNumber(dpy));
			fclose(stderr);
			fclose(stdout);
			execvp(conf.help_cmd[0],(char * const *)conf.help_cmd);
		}
	}
	else if (sym == XK_F2) {
		if ( (info->vis = !info->vis) ) XMapRaised(dpy,info->win);
		else XUnmapWindow(dpy,info->win);
		XFlush(dpy);
	}
	else if (sym == XK_e) {
		//mode = MODE_ERASE & (mode ^= MODE_ERASE);
		mode = (mode & MODE_ERASE ? 0 : MODE_ERASE);
		eraser_cursor(0,0);
		info->draw(info);
	}
	else if (sym == XK_c) {
		//mode = MODE_CROP & (mode ^= MODE_CROP);
		mode = (mode & MODE_CROP ? 0 : MODE_CROP);
		if (!(mode & MODE_CROP)) XDefineCursor(dpy, win, None);
		else XDefineCursor(dpy, win, XCreateFontCursor(dpy, 34));
		info->draw(info);
	}
	else if (sym == XK_Escape) {
		mode = MODE_NULL;
		XDefineCursor(dpy, win, None);
		info->draw(info);
	}
	else if (sym == XK_p) play(1.0);
	else if (sym == XK_t) {
		conf.layers = !conf.layers;
		spectro_draw();
		XCopyArea(dpy, buf, win, gc, 0, 0, ww, wh, 0, 0);
	}
	else if (sym == XK_u && mode & (MODE_ERASE)) erase(-1,-1);
	while(XCheckMaskEvent(dpy, KeyPressMask, ev));
}
コード例 #22
0
ファイル: handler.c プロジェクト: BIC-MNI/xdisp
/*---------------------------- HandleEvent --------------------------*/
int HandleEvent(XEvent *event)
{
  int	i;
    
  if(theEvent.xany.window==mainW) {

    switch (event->type) {
    case Expose: {
      XExposeEvent *exp_event = (XExposeEvent *) event;
 
      if (exp_event->window==mainW) {
	DrawWindow(exp_event->x,exp_event->y,
		   exp_event->width, exp_event->height);
      }
    }
    break;

    case EnterNotify: {
      if (Selected_Visual_Class==DirectColor)
	XStoreColors(theDisp,NewCmap,newC,ColorMapSize);
      if (Selected_Visual_Class!=TrueColor)
	XInstallColormap(theDisp,NewCmap);
    }
    break;
    
    case LeaveNotify: {
      if (Selected_Visual_Class==DirectColor)
	XStoreColors(theDisp,NewCmap,rootC,ColorMapSize); 
    }
    break;

    case KeyPress: {	/* allow a quit from the image window */
      Handle_KeyPress(event);
    }
    break;

    case MotionNotify: {
      Handle_Motion(event);
    }
    break;

    case ConfigureNotify: {
      XConfigureEvent *conf_event = (XConfigureEvent *) event;

      if (conf_event->window == cmdW && 
	  (conf_event->width != cmd_width ||
	   conf_event->height != cmd_height))
	XResizeWindow(theDisp,cmdW,cmd_width,cmd_height);
      if (conf_event->window == mainW && 
	  (conf_event->width != zWidth+(color_bar?color_bar_width:0) ||
	   conf_event->height != zHeight+info_height))
	Resize(conf_event->width-(color_bar?color_bar_width:0),
	       conf_event->height-info_height);
    }
    break;

    case ButtonPress: {
      if (theEvent.xbutton.button==Button1) {
	if (selzoom_active) {
	  Selective_Zoom((caddr_t)&one);
	  break;
	}
	XDefineCursor(theDisp,mainW,roiCursor);
	XFlush(theDisp);
	if (roi_present) draw_roi(roi_x1, roi_y1, roi_x2, roi_y2);
	roi_active = 1;
	roi_x1 = theEvent.xmotion.x < zWidth ?
	  (theEvent.xmotion.x>0 ?
	   theEvent.xmotion.x : 0) : zWidth-1;
	roi_y1 = theEvent.xmotion.y < zHeight ?
	  (theEvent.xmotion.y>0 ?
	   theEvent.xmotion.y : 0) : zHeight-1;
	roi_x2 = roi_x1;
	roi_y2 = roi_y1;
	draw_roi(roi_x1, roi_y1, roi_x2, roi_y2);
	break;
      } 
      if (theEvent.xbutton.button==Button2) {
	XDefineCursor(theDisp,mainW,wlCursor);
	XClearArea(theDisp,mainW,0,zHeight,
		   zWidth,zHeight+info_height,False);
	XDrawImageString(theDisp,mainW,theMGC,
			 zWidth-XTextWidth(ol_text_finfo,
					   wl_msg,strlen(wl_msg))-4,
			 zHeight+info_height-4,wl_msg,strlen(wl_msg));
	XDrawImageString(theDisp,mainW,theMGC,4,
			 zHeight+info_height-4,loc_msg,strlen(loc_msg));
	XFlush(theDisp);
	break;
      } 
      if (theEvent.xbutton.button==Button3) {
	/* note: not really 'iconic' anymore, simply map or unmap */
	if (cmdW_State==NormalState) {
	  XUnmapWindow(theDisp,cmdW);
	  cmdW_State = IconicState;
	}
	else {
	  XMapWindow(theDisp,cmdW);
	  cmdW_State = NormalState;
	}
	break;
      } 
    }
    break;

    case ButtonRelease: {
      int xa, xb, ya, yb;
      if (theEvent.xbutton.button==Button1 && roi_active) {
	roi_active = 0;
	xa = roi_x1*(Width-1)/(zWidth-1);
	xb = roi_x2*(Width-1)/(zWidth-1);
	ya = roi_y1*(Height-1)/(zHeight-1);
	yb = roi_y2*(Height-1)/(zHeight-1);
	roi_stats(xa, ya, xb, yb, 0);
	XDefineCursor(theDisp,mainW,mainCursor);
	XFlush(theDisp);
      }
      if (theEvent.xbutton.button==Button2) {
	XDefineCursor(theDisp,mainW,mainCursor);
	XFlush(theDisp);               
	if (Scale_Data && (oUpper != Upper || oLower != Lower)) {
	  Rescale();
	  Window_Level(Lower,Upper); 
	  oLower=Lower; oUpper=Upper; 
	}
	XClearArea(theDisp,mainW,0,zHeight,
		   zWidth,zHeight+info_height,False);
	if (wl_display) 
	  XDrawImageString(theDisp,mainW,theMGC,
			   zWidth-XTextWidth(ol_text_finfo,wl_msg,strlen(wl_msg))-4,
			   zHeight+info_height-4,wl_msg,strlen(wl_msg));
	XDrawImageString(theDisp,mainW,theMGC,4,
			 zHeight+info_height-4,loc_msg,strlen(loc_msg));
	update_sliders();
	update_msgs();
      }
    }
    break;

    case UnmapNotify: {
      if (bitmap_pad==8) {
	if (Interpolation_Type==BILINEAR) {
	  bilinear_byte_to_byte(byte_Image, Width, Height,
				icon_byte_image, ICON_WIDTH, ICON_HEIGHT);
	}
	else {
	  nneighbour_byte_to_byte(byte_Image, Width, Height,
				  icon_byte_image, ICON_WIDTH, ICON_HEIGHT);
	}
      }
      else {
	if (Interpolation_Type==BILINEAR) {
	  bilinear_rgbp_to_rgbp(byte_Image, Width, Height,
				icon_byte_image, ICON_WIDTH, ICON_HEIGHT);
	}
	else {
	  nneighbour_rgbp_to_rgbp(byte_Image, Width, Height,
				  icon_byte_image, ICON_WIDTH, ICON_HEIGHT);
	}
      }
      XPutImage(theDisp,iconW,theMGC,iconImage,0,0,0,0,
		ICON_WIDTH, ICON_HEIGHT);
    }
    break;
                
    case CirculateNotify:
    case MapNotify:
    case DestroyNotify:
    case GravityNotify:
    case ReparentNotify:
    default: 
    break;
    }  /* end of switch */
  }

  /* other command Window events */
  if(theEvent.xany.window==cmdW) {

    switch (event->type) {
    case Expose: {
      update_msgs();
    }
    break;

    case EnterNotify: {
      if (Selected_Visual_Class==DirectColor)
	XStoreColors(theDisp,NewCmap,newC,ColorMapSize); 
      if (Selected_Visual_Class!=TrueColor)
	XInstallColormap(theDisp,NewCmap);
    }
    break;

    case LeaveNotify: {
      if (Selected_Visual_Class==DirectColor)
	XStoreColors(theDisp,NewCmap,rootC,ColorMapSize); 
    }
    break;

    case UnmapNotify: {
      cmdW_State = IconicState;
    }
    break;
            
    case MapNotify: {
      cmdW_State = NormalState;
    }
    break;

    case ConfigureNotify: {
      XConfigureEvent *conf_event = (XConfigureEvent *) event;

      if (conf_event->window == cmdW && 
	  (conf_event->width != cmd_width ||
	   conf_event->height != cmd_height))
	XResizeWindow(theDisp,cmdW,cmd_width,cmd_height);
    }
    break;

    default: break;
    }
  }

  /* button press events */
  if (XFindContext(theDisp, theEvent.xany.window, xwin_context,
		   (caddr_t *) &which_xwin)==0) {
    if(*(which_xwin->event_handler)!=NULL)
      (*(which_xwin->event_handler))(which_xwin);
    if (Scale_Data && (oUpper != Upper || oLower != Lower)) {
      Rescale();
      oLower=Lower; oUpper=Upper;
    }
  }
}
コード例 #23
0
ファイル: MainNoGUI.cpp プロジェクト: Krude/dolphin
void X11_MainLoop()
{
	bool fullscreen = SConfig::GetInstance().m_LocalCoreStartupParameter.bFullscreen;
	while (!Core::IsRunning())
		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();
}
コード例 #24
0
ファイル: w_fontpanel.c プロジェクト: coliveira/xfignew
void
setup_fontmenu(void)
{
    register int    i;

    DeclareArgs(2);

    Pixel	    bg, fg;

    /* get the foreground/background of the widget */
    FirstArg(XtNforeground, &fg);
    NextArg(XtNbackground, &bg);
    GetValues(ps_fontpane[0]);

    /* Create the bitmaps */

#ifdef I18N
    if (appres.international) {
      char *lang;
      lang = appres.font_menu_language;
      if (lang[0] == '\0') lang = setlocale(LC_CTYPE, NULL);
      if (strncasecmp(lang, "japanese", 2) == 0) {
	extern unsigned char Japanese_Times_Roman_bits[], Japanese_Roman_bits[];
	extern unsigned char Japanese_Times_Bold_bits[], Japanese_Bold_bits[];
	psfont_menu_bits[1] = Japanese_Times_Roman_bits;
	latexfont_menu_bits[1] = Japanese_Roman_bits;
	psfont_menu_bits[3] = Japanese_Times_Bold_bits;
	latexfont_menu_bits[2] = Japanese_Bold_bits;
      } else if (strncasecmp(lang, "korean", 2) == 0) {
	extern unsigned char Korean_Times_Roman_bits[], Korean_Roman_bits[];
	extern unsigned char Korean_Times_Bold_bits[], Korean_Bold_bits[];
	psfont_menu_bits[1] = Korean_Times_Roman_bits;
	latexfont_menu_bits[1] = Korean_Roman_bits;
	psfont_menu_bits[3] = Korean_Times_Bold_bits;
	latexfont_menu_bits[2] = Korean_Bold_bits;
      }
    }
#endif  /* I18N */
    for (i = 0; i < NUM_FONTS + 1; i++)
	psfont_menu_bitmaps[i] = XCreatePixmapFromBitmapData(tool_d,
				   XtWindow(ind_panel), (char *) psfont_menu_bits[i],
				     PS_FONTPANE_WD, PS_FONTPANE_HT, fg, bg,
				      tool_dpth);

    for (i = 0; i < NUM_LATEX_FONTS; i++)
	latexfont_menu_bitmaps[i] = XCreatePixmapFromBitmapData(tool_d,
				     XtWindow(ind_panel), (char *) latexfont_menu_bits[i],
				      LATEX_FONTPANE_WD, LATEX_FONTPANE_HT, fg, bg,
				       tool_dpth);

    /* Store the bitmaps in the menu panes */
    for (i = 0; i < NUM_FONTS + 1; i++) {
	FirstArg(XtNbitmap, psfont_menu_bitmaps[i]);
	SetValues(ps_fontpane[i]);
    }
    for (i = 0; i < NUM_LATEX_FONTS; i++) {
	FirstArg(XtNbitmap, latexfont_menu_bitmaps[i]);
	SetValues(latex_fontpane[i]);
    }

    XtRealizeWidget(ps_fontmenu);
    XtRealizeWidget(latex_fontmenu);
    /* at this point the windows are realized but not drawn */
    XDefineCursor(tool_d, XtWindow(ps_fontpanes), arrow_cursor);
    XDefineCursor(tool_d, XtWindow(latex_fontpanes), arrow_cursor);
}
コード例 #25
0
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nDefineCursor(JNIEnv *env, jclass unused, jlong display_ptr, jlong window_ptr, jlong cursor_ptr) {
	Display *disp = (Display *)(intptr_t)display_ptr;
	Window win = (Window)window_ptr;
	Cursor cursor = (Cursor)cursor_ptr;
	XDefineCursor(disp, win, cursor);
}
コード例 #26
0
void CL_DisplayWindow_OpenGL::show_system_cursor()
{
	XDefineCursor(disp, window, system_cursor);
}
コード例 #27
0
ファイル: support.c プロジェクト: PDKK/doubleHexapod
// only used internally
void makeNativeWindow()
{

#ifdef __FOR_XORG__

    __x_display = XOpenDisplay(NULL);	// open the standard display (the primary screen)
    if (__x_display == NULL) {
        printf("cannot connect to X server\n");
    }

    Window root = DefaultRootWindow(__x_display);	// get the root window (usually the whole screen)


    XSetWindowAttributes swa;
    swa.event_mask =
        ExposureMask | PointerMotionMask | KeyPressMask | KeyReleaseMask;

    __display_width=640;
    __display_height=480;  // xorg hard coded for now
    int s = DefaultScreen(__x_display);
    __win = XCreateSimpleWindow(__x_display, root,
                                10, 10, __display_width, __display_height, 1,
                                BlackPixel(__x_display, s),
                                WhitePixel(__x_display, s));
    XSelectInput(__x_display, __win, ExposureMask |
                 KeyPressMask | KeyReleaseMask |
                 ButtonPressMask | ButtonReleaseMask | PointerMotionMask);

    XSetWindowAttributes xattr;
    Atom atom;
    int one = 1;

    xattr.override_redirect = False;
    XChangeWindowAttributes(__x_display, __win, CWOverrideRedirect, &xattr);

    /*
    	atom = XInternAtom(__x_display, "_NET_WM_STATE_FULLSCREEN", True);
    	XChangeProperty(__x_display, win,
    			XInternAtom(__x_display, "_NET_WM_STATE", True),
    			XA_ATOM, 32, PropModeReplace, (unsigned char *)&atom,
    			1);
    */

    XWMHints hints;
    hints.input = True;
    hints.flags = InputHint;
    XSetWMHints(__x_display, __win, &hints);

    XMapWindow(__x_display, __win);	// make the window visible on the screen
    XStoreName(__x_display, __win, "GLES2.0 framework");	// give the window a name

    // NB - RPi needs to use EGL_DEFAULT_DISPLAY that some X configs dont seem to like
    __egl_display = eglGetDisplay((EGLNativeDisplayType) __x_display);
    if (__egl_display == EGL_NO_DISPLAY) {
        printf("Got no EGL display.\n");
    }

    __eventWin = __win;




    Cursor invisibleCursor;
    Pixmap bitmapNoData;
    XColor black;
    static char noData[] = { 0,0,0,0,0,0,0,0 };
    black.red = black.green = black.blue = 0;

    bitmapNoData = XCreateBitmapFromData(__x_display, __win, noData, 8, 8);
    invisibleCursor = XCreatePixmapCursor(__x_display, bitmapNoData, bitmapNoData,
                                          &black, &black, 0, 0);
    XDefineCursor(__x_display,__win, invisibleCursor);
    XFreeCursor(__x_display, invisibleCursor);


#endif				//__FOR_XORG__

#ifdef __FOR_RPi__

    bcm_host_init();

    int32_t success = 0;


    // create an EGL window surface, passing context width/height
    success = graphics_get_display_size(0 /* LCD */ , &__display_width,
                                        &__display_height);
    if (success < 0) {
        printf("unable to get display size\n");
        //return EGL_FALSE;
    }


    __x_display = XOpenDisplay(NULL);	// open the standard display (the primary screen)
    if (__x_display == NULL) {
        printf("cannot connect to X server\n");
    }

    Window root = DefaultRootWindow(__x_display);	// get the root window (usually the whole screen)

    XSetWindowAttributes swa;
    swa.event_mask =
        ExposureMask | PointerMotionMask | KeyPressMask | KeyReleaseMask;

    int s = DefaultScreen(__x_display);
    __eventWin = XCreateSimpleWindow(__x_display, root,
                                     0, 0, __display_width, __display_height, 1,
                                     BlackPixel(__x_display, s),
                                     WhitePixel(__x_display, s));
    XSelectInput(__x_display, __eventWin, ExposureMask |
                 KeyPressMask | KeyReleaseMask |
                 ButtonPressMask | ButtonReleaseMask | PointerMotionMask);

    XSetWindowAttributes xattr;
    Atom atom;
    int one = 1;

    xattr.override_redirect = False;
    XChangeWindowAttributes(__x_display, __eventWin, CWOverrideRedirect,
                            &xattr);

    XWMHints hints;
    hints.input = True;
    hints.flags = InputHint;
    XSetWMHints(__x_display, __eventWin, &hints);

    XMapWindow(__x_display, __eventWin);	// make the window visible on the screen
    XStoreName(__x_display, __eventWin, "Event trap");	// give the window a name

    // we have to be full screen to capture all mouse events
    // TODO consider using warp mouse to report relative motions
    // instead of absolute...

    XFlush(__x_display);	// you have to flush or bcm seems to prevent window coming up?

    Atom wmState = XInternAtom(__x_display, "_NET_WM_STATE", False);
    Atom fullScreen = XInternAtom(__x_display,
                                  "_NET_WM_STATE_FULLSCREEN", False);
    XEvent xev;
    xev.xclient.type = ClientMessage;
    xev.xclient.serial = 0;
    xev.xclient.send_event = True;
    xev.xclient.window = __eventWin;
    xev.xclient.message_type = wmState;
    xev.xclient.format = 32;
    xev.xclient.data.l[0] = 1;	//_NET_WM_STATE_ADD
    xev.xclient.data.l[1] = fullScreen;
    xev.xclient.data.l[2] = 0;
    XSendEvent(__x_display, root, False,
               SubstructureRedirectMask | SubstructureNotifyMask, &xev);

    XFlush(__x_display);	// you have to flush or bcm seems to prevent window coming up?

    static EGL_DISPMANX_WINDOW_T nativewindow;

    DISPMANX_ELEMENT_HANDLE_T dispman_element;
    DISPMANX_DISPLAY_HANDLE_T dispman_display;
    DISPMANX_UPDATE_HANDLE_T dispman_update;
    VC_RECT_T dst_rect;
    VC_RECT_T src_rect;



//	printf("display size %i,%i\n",__display_width,__display_height);


    dst_rect.x = 0;
    dst_rect.y = 0;
    dst_rect.width = __display_width;
    dst_rect.height = __display_height;



    src_rect.x = 0;
    src_rect.y = 0;
    src_rect.width = __display_width << 16;
    src_rect.height = __display_height << 16;

    dispman_display = vc_dispmanx_display_open(0 /* LCD */ );
    dispman_update = vc_dispmanx_update_start(0);

    //VC_DISPMANX_ALPHA_T alpha = { DISPMANX_FLAGS_ALPHA_FROM_SOURCE | DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS,255,0 };
    VC_DISPMANX_ALPHA_T alpha = { DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS,255,0 };
    dispman_element =
        vc_dispmanx_element_add(dispman_update, dispman_display,
                                0 /*layer */ , &dst_rect, 0 /*src */ ,
                                &src_rect, DISPMANX_PROTECTION_NONE,
                                &alpha /*alpha */ , 0 /*clamp */ ,
                                0 /*transform */ );

    nativewindow.element = dispman_element;
    nativewindow.width = __display_width;
    nativewindow.height = __display_height;
    vc_dispmanx_update_submit_sync(dispman_update);

    __win = &nativewindow;

    __egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);

#endif				//__FOR_RPi__

#ifdef __FOR_RPi_noX__

    bcm_host_init();

    int32_t success = 0;

    success = graphics_get_display_size(0 /* LCD */ , &__display_width,
                                        &__display_height);
    if (success < 0) {
        printf("unable to get display size\n");
        //return EGL_FALSE;
    }


    static EGL_DISPMANX_WINDOW_T nativewindow;

    DISPMANX_ELEMENT_HANDLE_T dispman_element;
    DISPMANX_DISPLAY_HANDLE_T dispman_display;
    DISPMANX_UPDATE_HANDLE_T dispman_update;
    VC_RECT_T dst_rect;
    VC_RECT_T src_rect;


    dst_rect.x = 0;
    dst_rect.y = 0;
    dst_rect.width = __display_width;
    dst_rect.height = __display_height;

    src_rect.x = 0;
    src_rect.y = 0;
    src_rect.width = __display_width << 16;
    src_rect.height = __display_height << 16;

    dispman_display = vc_dispmanx_display_open(0 /* LCD */ );
    dispman_update = vc_dispmanx_update_start(0);

    VC_DISPMANX_ALPHA_T alpha = { DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS,255,0 };
    dispman_element =
        vc_dispmanx_element_add(dispman_update, dispman_display,
                                0 /*layer */ , &dst_rect, 0 /*src */ ,
                                &src_rect, DISPMANX_PROTECTION_NONE,
                                &alpha /*alpha */ , 0 /*clamp */ ,
                                0 /*transform */ );

    nativewindow.element = dispman_element;
    nativewindow.width = __display_width;
    nativewindow.height = __display_height;
    vc_dispmanx_update_submit_sync(dispman_update);

    __win = &nativewindow;

    __egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    if (__egl_display == EGL_NO_DISPLAY) {
        printf("Got no EGL display.\n");
    }

#endif //__FOR_RPi_noX__


}
コード例 #28
0
void CL_DisplayWindow_OpenGL::hide_system_cursor()
{
	XDefineCursor(disp, window, hidden_cursor);
}
コード例 #29
0
ファイル: x11_main.c プロジェクト: adan91/gd-pdfview
static void winopen(void)
{
	XWMHints *wmhints;
	XClassHint *classhint;

	xdpy = XOpenDisplay(NULL);
	if (!xdpy)
		fz_throw(gapp.ctx, FZ_ERROR_GENERIC, "cannot open display");

	XA_CLIPBOARD = XInternAtom(xdpy, "CLIPBOARD", False);
	XA_TARGETS = XInternAtom(xdpy, "TARGETS", False);
	XA_TIMESTAMP = XInternAtom(xdpy, "TIMESTAMP", False);
	XA_UTF8_STRING = XInternAtom(xdpy, "UTF8_STRING", False);
	WM_DELETE_WINDOW = XInternAtom(xdpy, "WM_DELETE_WINDOW", False);
	NET_WM_STATE = XInternAtom(xdpy, "_NET_WM_STATE", False);
	NET_WM_STATE_FULLSCREEN = XInternAtom(xdpy, "_NET_WM_STATE_FULLSCREEN", False);
	WM_RELOAD_PAGE = XInternAtom(xdpy, "_WM_RELOAD_PAGE", False);

	xscr = DefaultScreen(xdpy);

	ximage_init(xdpy, xscr, DefaultVisual(xdpy, xscr));

	xcarrow = XCreateFontCursor(xdpy, XC_left_ptr);
	xchand = XCreateFontCursor(xdpy, XC_hand2);
	xcwait = XCreateFontCursor(xdpy, XC_watch);
	xccaret = XCreateFontCursor(xdpy, XC_xterm);

	xbgcolor.red = 0x7000;
	xbgcolor.green = 0x7000;
	xbgcolor.blue = 0x7000;

	xshcolor.red = 0x4000;
	xshcolor.green = 0x4000;
	xshcolor.blue = 0x4000;

	XAllocColor(xdpy, DefaultColormap(xdpy, xscr), &xbgcolor);
	XAllocColor(xdpy, DefaultColormap(xdpy, xscr), &xshcolor);

	xwin = XCreateWindow(xdpy, DefaultRootWindow(xdpy),
		10, 10, 200, 100, 0,
		ximage_get_depth(),
		InputOutput,
		ximage_get_visual(),
		0,
		NULL);
	if (xwin == None)
		fz_throw(gapp.ctx, FZ_ERROR_GENERIC, "cannot create window");

	XSetWindowColormap(xdpy, xwin, ximage_get_colormap());
	XSelectInput(xdpy, xwin,
		StructureNotifyMask | ExposureMask | KeyPressMask |
		PointerMotionMask | ButtonPressMask | ButtonReleaseMask);

	mapped = 0;

	xgc = XCreateGC(xdpy, xwin, 0, NULL);

	XDefineCursor(xdpy, xwin, xcarrow);

	wmhints = XAllocWMHints();
	if (wmhints)
	{
		wmhints->flags = IconPixmapHint | IconMaskHint;
		xicon = XCreateBitmapFromData(xdpy, xwin,
			(char*)mupdf_icon_bitmap_16_bits,
			mupdf_icon_bitmap_16_width,
			mupdf_icon_bitmap_16_height);
		xmask = XCreateBitmapFromData(xdpy, xwin,
			(char*)mupdf_icon_bitmap_16_mask_bits,
			mupdf_icon_bitmap_16_mask_width,
			mupdf_icon_bitmap_16_mask_height);
		if (xicon && xmask)
		{
			wmhints->icon_pixmap = xicon;
			wmhints->icon_mask = xmask;
			XSetWMHints(xdpy, xwin, wmhints);
		}
		XFree(wmhints);
	}

	classhint = XAllocClassHint();
	if (classhint)
	{
		classhint->res_name = "mupdf";
		classhint->res_class = "MuPDF";
		XSetClassHint(xdpy, xwin, classhint);
		XFree(classhint);
	}

	XSetWMProtocols(xdpy, xwin, &WM_DELETE_WINDOW, 1);

	x11fd = ConnectionNumber(xdpy);
}
コード例 #30
0
int wincreat( int x, int y, int width, int height, char *title)
{ 
  XSetWindowAttributes   swa; 
  Colormap               cmap;
  XVisualInfo           *vi;
  int                    dummy;
  GLXContext             glcx;
  XEvent                 event;
  int                    attributes[] = { GLX_RGBA,
                                          GLX_DEPTH_SIZE, 16,
                                          GLX_RED_SIZE, 8,
                                          GLX_GREEN_SIZE, 8,
                                          GLX_BLUE_SIZE, 8,
                                          GLX_ALPHA_SIZE, 8,
                                          GLX_DOUBLEBUFFER,
                                          None }; 

    if( !(dpy = XOpenDisplay( NULL )) )    /* defaults to $DISPLAY */
  {
      fprintf( stderr, "Unable to open display.\n" );
      exit( 1 );

  } else {

    /*printf( "Connected to display... %s (%s).\n", dpy->display_name, dpy->vendor );*/

  }   /* end if( ) */

  if( !glXQueryExtension( dpy, &dummy, &dummy ) )
  {
      fprintf( stderr, "Unable to query GLX extensions.\n" );
      exit( 1 );

  }   /* end if( ) */

  if( !(vi = glXChooseVisual( dpy, DefaultScreen( dpy ), attributes )) )
  {
      fprintf( stderr, "Unable get a visual.\n" );
      exit( 1 );

  }   /* end if( ) */

  if( vi->class != TrueColor )
  {
      fprintf( stderr, "Need TrueColor class.\n" );
      exit( 1 );
  }

  if( !(glcx = glXCreateContext( dpy, vi, None, GL_TRUE )) )
  {
      fprintf( stderr, "Unable create a GL context.\n" );
      exit( 1 );

  }   /* end if( ) */

  cmap = XCreateColormap( dpy, RootWindow( dpy, vi->screen ),
                                     vi->visual, AllocNone );

  swa.colormap                  = cmap;
  swa.border_pixel              = 0;
  swa.event_mask                = ExposureMask
                                | KeyPressMask
                                | StructureNotifyMask;

  glwin = XCreateWindow(        dpy,
                                RootWindow( dpy, vi->screen ),
                                x,
                                y,
                                width,
                                height,
                                0,
                                vi->depth,
                                InputOutput,
                                vi->visual,
                                CWBorderPixel   |
                                CWColormap      |
                                CWEventMask,
                                &swa
                        );

/* Make a clear cursor so it looks like we have none. */
  {
      Pixmap pixmap;
      Cursor cursor;
      XColor color;
      char clear_bits[32];

      memset(clear_bits, 0, sizeof(clear_bits));

      pixmap = XCreatePixmapFromBitmapData(dpy, glwin, clear_bits,
                                           16, 16, 1, 0, 1);
      cursor = XCreatePixmapCursor(dpy, pixmap, pixmap, &color, &color, 8, 8);
      XDefineCursor(dpy, glwin, cursor);

      XFreePixmap(dpy, pixmap);
  }


  XSetStandardProperties( dpy, glwin, title, title, None, NULL, 0, NULL );

  if( !glXMakeCurrent( dpy, glwin, glcx ) )
  {
      fprintf( stderr, "Failed to make the GL context current.\n" );
      exit( 1 );
  }

  XMapWindow( dpy, glwin );
  XIfEvent( dpy, &event, WaitForMapNotify, (char *)glwin );

  return( 1 );

} /* end int APIENTRY pglc_wincreat( ) */