Example #1
0
// ---------------------------------------------------------------------------
void X11WindowImpl::bringToTop(int stay)
{
  XRaiseWindow(factory->xdisplay, xwindow);
  factory->flushX();
}
Example #2
0
char *
get_more_input (char *prompt, char *preinput, int history_id,
                completion_fn compl_fn)
{
  /* Emacs 21 uses a 513 byte string to store the keysym name. */
  char keysym_buf[513];
  rp_screen *s = current_screen ();
  KeySym ch;
  unsigned int modifier;
  rp_input_line *line;
  char *final_input;
  edit_status status;
  Window focus;
  int revert, done = 0;

  history_reset();

  /* Create our line structure */
  line = input_line_new (prompt, preinput, history_id, compl_fn);

  /* We don't want to draw overtop of the program bar. */
  hide_bar (s);

  /* Switch to the default colormap. */
  if (current_window())
    XUninstallColormap (dpy, current_window()->colormap);
  XInstallColormap (dpy, s->def_cmap);

  XMapWindow (dpy, s->input_window);
  XRaiseWindow (dpy, s->input_window);
  XClearWindow (dpy, s->input_window);
  /* Switch focus to our input window to read the next key events. */
  XGetInputFocus (dpy, &focus, &revert);
  set_window_focus (s->input_window);
  XSync (dpy, False);

  update_input_window (s, line);

  while (!done)
    {
      read_key (&ch, &modifier, keysym_buf, sizeof (keysym_buf));
      modifier = x11_mask_to_rp_mask (modifier);
      PRINT_DEBUG (("ch = %ld, modifier = %d, keysym_buf = %s",
                    ch, modifier, keysym_buf));
      status = execute_edit_action (line, ch, modifier, keysym_buf);

      switch (status)
        {
        case EDIT_COMPLETE:
        case EDIT_DELETE:
        case EDIT_INSERT:
        case EDIT_MOVE:
          /* If the text changed (and we didn't just complete
             something) then set the virgin bit. */
          if (status != EDIT_COMPLETE)
            line->compl->virgin = 1;
          /* In all cases, we need to redisplay the input string. */
          update_input_window (s, line);
          break;
        case EDIT_NO_OP:
          ring_bell ();
          break;
        case EDIT_ABORT:
          final_input = NULL;
          done = 1;
          break;
        case EDIT_DONE:
          final_input = xstrdup (line->buffer);
          done = 1;
          break;
        default:
          PRINT_ERROR (("Unhandled status %d; this is a *BUG*\n", status));
          exit (EXIT_FAILURE);
        }
    }

  /* Clean up our line structure */
  input_line_free (line);

  /* Revert focus. */
  set_window_focus (focus);
  XUnmapWindow (dpy, s->input_window);

  /* Possibly restore colormap. */
  if (current_window())
    {
      XUninstallColormap (dpy, s->def_cmap);
      XInstallColormap (dpy, current_window()->colormap);
    }

  return final_input;
}
Example #3
0
/* read an X event */
void ReadXServer (void)
{
  static XEvent event;
  int old_cursor = 0, keypress;
  Item *item, *old_item;
  KeySym ks;
  char *sp, *dp;
  static unsigned char buf[10];         /* unsigned for international */
  static int n;

  while (FEventsQueued(dpy, QueuedAfterReading)) {
    FNextEvent(dpy, &event);
    if (event.xany.window == CF.frame) {
      switch (event.type) {
      case ClientMessage:
      {
	      if(event.xclient.format == 32 &&
		 event.xclient.data.l[0] == wm_del_win)
	      {
		      exit(0);
	      }
      }
      break;
      case ConfigureNotify:             /* has window be reconfigured */
      {
	      XEvent tmpe;

	      while (FCheckTypedWindowEvent(
		      dpy, CF.frame, ConfigureNotify, &tmpe))
	      {
		      if (!tmpe.xconfigure.send_event)
			      continue;
		      event.xconfigure.x = tmpe.xconfigure.x;
		      event.xconfigure.y = tmpe.xconfigure.y;
		      event.xconfigure.send_event = True;
	      }
	      if (CF.max_width != event.xconfigure.width ||
		  CF.total_height != event.xconfigure.height)
	      {
		      /* adjust yourself... do noting */
		      ResizeFrame();
		      CF.max_width = event.xconfigure.width;
		      CF.total_height = event.xconfigure.height;
		      UpdateRootTransapency(False, True);
		      if (!CSET_IS_TRANSPARENT(colorset))
		      {
			  RedrawFrame(NULL);
		      }
	      }
	      else if (event.xconfigure.send_event)
	      {
		      UpdateRootTransapency(False, True);
	      }
      }
      break;
#if 0
      case SelectionClear:
	 selection_clear ();
	break;
      case SelectionNotify:
	selection_paste ();
	break;
      case SelectionRequest:
	 selection_send ();
	break;
#endif
      case Expose:
      {
	      int ex = event.xexpose.x;
	      int ey = event.xexpose.y;
	      int ex2 = event.xexpose.x + event.xexpose.width;
	      int ey2 = event.xexpose.y + event.xexpose.height;
	      while (FCheckTypedWindowEvent(dpy, CF.frame, Expose, &event))
	      {
		      ex = min(ex, event.xexpose.x);
		      ey = min(ey, event.xexpose.y);
		      ex2 = max(ex2, event.xexpose.x + event.xexpose.width);
		      ey2 = max(ey2 , event.xexpose.y + event.xexpose.height);
	      }
	      event.xexpose.x = ex;
	      event.xexpose.y = ey;
	      event.xexpose.width = ex2 - ex;
	      event.xexpose.height = ey2 - ey;
	      RedrawFrame(&event);
	      if (CF.grab_server && !CF.server_grabbed)
	      {
		      if (GrabSuccess ==
			  XGrabPointer(dpy, CF.frame, True, 0,
				       GrabModeAsync, GrabModeAsync,
				       None, None, CurrentTime))
			      CF.server_grabbed = 1;
	      }
      }
      break;
      case VisibilityNotify:
	if (CF.server_grabbed &&
	    event.xvisibility.state != VisibilityUnobscured)
	{
	  /* raise our window to the top */
	  XRaiseWindow(dpy, CF.frame);
	  XSync(dpy, 0);
	}
	break;
      case KeyPress:  /* we do text input here */
	n = XLookupString(&event.xkey, (char *)buf, sizeof(buf), &ks, NULL);
	keypress = buf[0];
	myfprintf((stderr, "Keypress [%s]\n", buf));
	if (n == 0) {  /* not a regular key, translate it into one */
	  switch (ks) {
	  case XK_Home:
	  case XK_Begin:
	    buf[0] = '\001';  /* ^A */
	    break;
	  case XK_End:
	    buf[0] = '\005';  /* ^E */
	    break;
	  case XK_Left:
	    buf[0] = '\002';  /* ^B */
	    break;
	  case XK_Right:
	    buf[0] = '\006';  /* ^F */
	    break;
	  case XK_Up:
	    buf[0] = '\020';            /* ^P */
	    break;
	  case XK_Down:
	    buf[0] = '\016';  /* ^N */
	    break;
	  default:
	    if (ks >= XK_F1 && ks <= XK_F35) {
	      buf[0] = '\0';
	      keypress = 257 + ks - XK_F1;
	    } else
	      goto no_redraw;  /* no action for this event */
	  }
	}
	switch (ks) {                   /* regular key, may need adjustment */
	case XK_Tab:
#ifdef XK_XKB_KEYS
	case XK_ISO_Left_Tab:
#endif
	  if (event.xkey.state & ShiftMask) { /* shifted key */
	    buf[0] = '\020';          /* chg shift tab to ^P */
	  }
	  break;
	case '>':
	  if (event.xkey.state & Mod1Mask) { /* Meta, shift > */
	    process_history(1);
	    goto redraw_newcursor;
	  }
	  break;
	case '<':
	  if (event.xkey.state & Mod1Mask) { /* Meta, shift < */
	    process_history(-1);
	    goto redraw_newcursor;
	  }
	  break;
	}
	if (!CF.cur_input) {  /* no text input fields */
	  for (item = root_item_ptr; item != 0;
	       item = item->header.next) {/* all items */
	    if (item->type == I_BUTTON && item->button.keypress == keypress) {
	      RedrawItem(item, 1, NULL);
	      usleep(MICRO_S_FOR_10MS);
	      RedrawItem(item, 0, NULL);
	      DoCommand(item);
	      goto no_redraw;
	    }
	  }
	  break;
	} else if (CF.cur_input == CF.cur_input->input.next_input) {
	  /* 1 ip field */
	  switch (buf[0]) {
	  case '\020':                  /* ^P previous field */
	    process_history(-1);
	    goto redraw_newcursor;
	    break;
	  case '\016':                  /* ^N  next field */
	    process_history(1);
	    goto redraw_newcursor;
	    break;
	  } /* end switch */
	} /* end one input field */
	switch (buf[0]) {
	case '\001':  /* ^A */
	  old_cursor = CF.abs_cursor;
	  CF.rel_cursor = 0;
	  CF.abs_cursor = 0;
	  CF.cur_input->input.left = 0;
	  goto redraw_newcursor;
	  break;
	case '\005':  /* ^E */
	  old_cursor = CF.abs_cursor;
	  CF.rel_cursor = CF.cur_input->input.n;
	  if ((CF.cur_input->input.left =
	       CF.rel_cursor - CF.cur_input->input.size) < 0)
	    CF.cur_input->input.left = 0;
	  CF.abs_cursor = CF.rel_cursor - CF.cur_input->input.left;
	  goto redraw_newcursor;
	  break;
	case '\002':  /* ^B */
	  old_cursor = CF.abs_cursor;
	  if (CF.rel_cursor > 0) {
	    CF.rel_cursor--;
	    CF.abs_cursor--;
	    if (CF.abs_cursor <= 0 && CF.rel_cursor > 0) {
	      CF.abs_cursor++;
	      CF.cur_input->input.left--;
	    }
	  }
	  goto redraw_newcursor;
	  break;
	case '\006':  /* ^F */
	  old_cursor = CF.abs_cursor;
	  if (CF.rel_cursor < CF.cur_input->input.n) {
	    CF.rel_cursor++;
	    CF.abs_cursor++;
	    if (CF.abs_cursor >= CF.cur_input->input.size &&
		CF.rel_cursor < CF.cur_input->input.n) {
	      CF.abs_cursor--;
	      CF.cur_input->input.left++;
	    }
	  }
	  goto redraw_newcursor;
	  break;
	case '\010':  /* ^H */
	  old_cursor = CF.abs_cursor;
	  if (CF.rel_cursor > 0) {
	    sp = CF.cur_input->input.value + CF.rel_cursor;
	    dp = sp - 1;
	    for (; *dp = *sp, *sp != '\0'; dp++, sp++);
	    CF.cur_input->input.n--;
	    CF.rel_cursor--;
	    if (CF.rel_cursor < CF.abs_cursor) {
	      CF.abs_cursor--;
	      if (CF.abs_cursor <= 0 && CF.rel_cursor > 0) {
		CF.abs_cursor++;
		CF.cur_input->input.left--;
	      }
	    } else
	      CF.cur_input->input.left--;
	  }
	  goto redraw_newcursor;
	  break;
	case '\177':  /* DEL */
	case '\004':  /* ^D */
	  if (CF.rel_cursor < CF.cur_input->input.n) {
	    sp = CF.cur_input->input.value + CF.rel_cursor + 1;
	    dp = sp - 1;
	    for (; *dp = *sp, *sp != '\0'; dp++, sp++);
	    CF.cur_input->input.n--;
	    goto redraw_newcursor;
	  }
	  break;
	case '\013':  /* ^K */
	  CF.cur_input->input.value[CF.rel_cursor] = '\0';
	  CF.cur_input->input.n = CF.rel_cursor;
	  goto redraw_newcursor;
	case '\025':  /* ^U */
	  CF.cur_input->input.value[0] = '\0';
	  CF.cur_input->input.n = CF.cur_input->input.left = 0;
	  CF.rel_cursor = CF.abs_cursor = 0;
	  goto redraw_newcursor;
	case '\020':                    /* ^P previous field */
	  old_item = CF.cur_input;
	  CF.cur_input = old_item->input.prev_input; /* new current input fld */
	  RedrawItem(old_item, 1, NULL);
	  CF.rel_cursor = CF.abs_cursor = 0; /* home cursor in new input field */
	  goto redraw;
	  break;
	case '\t':
	case '\n':
	case '\015':
	case '\016':  /* LINEFEED, TAB, RETURN, ^N, jump to the next field */
	  switch (process_tabtypes(&buf[0])) {
	    case 0: goto no_redraw;break;
	    case 1: goto redraw;break;
	  }
	  break;
	default:
	  old_cursor = CF.abs_cursor;
	  if((buf[0] >= ' ' &&
	      buf[0] < '\177') ||
	     (buf[0] >= 160)) {         /* regular or intl char */
	    process_regular_char_input(&buf[0]); /* insert into input field */
	    goto redraw_newcursor;
	  }
	  /* unrecognized key press, check for buttons */
	  for (item = root_item_ptr; item != 0; item = item->header.next)
	  {
	    /* all items */
	    myfprintf((stderr, "Button: keypress==%d\n",
		    item->button.keypress));
	    if (item->type == I_BUTTON && item->button.keypress == keypress) {
	      RedrawItem(item, 1, NULL);
	      usleep(MICRO_S_FOR_10MS);  /* .1 seconds */
	      RedrawItem(item, 0, NULL);
	      DoCommand(item);
	      goto no_redraw;
	    }
	  }
	  break;
	}
      redraw_newcursor:
	{
	  XSetForeground(dpy, CF.cur_input->header.dt_ptr->dt_item_GC,
			 CF.cur_input->header.dt_ptr->dt_colors[c_item_bg]);
	  /* Since DrawString is being used, I changed this to clear the
	     entire input field.  dje 10/24/99. */
	  XClearArea(dpy, CF.cur_input->header.win,
		     BOX_SPC + TEXT_SPC - 1, BOX_SPC,
		     CF.cur_input->header.size_x
		     - (2 * BOX_SPC) - 2 - TEXT_SPC,
		     (CF.cur_input->header.size_y - 1)
		     - 2 * BOX_SPC + 1, False);
	}
      redraw:
	{
	  int len, x, dy;
	  len = CF.cur_input->input.n - CF.cur_input->input.left;
	  XSetForeground(dpy, CF.cur_input->header.dt_ptr->dt_item_GC,
			 CF.cur_input->header.dt_ptr->dt_colors[c_item_fg]);
	  if (len > CF.cur_input->input.size)
	    len = CF.cur_input->input.size;
	  CF.cur_input->header.dt_ptr->dt_Fstr->win = CF.cur_input->header.win;
	  CF.cur_input->header.dt_ptr->dt_Fstr->gc  =
	    CF.cur_input->header.dt_ptr->dt_item_GC;
	  CF.cur_input->header.dt_ptr->dt_Fstr->flags.has_colorset = False;
	  if (itemcolorset >= 0)
	  {
	    CF.cur_input->header.dt_ptr->dt_Fstr->colorset =
		    &Colorset[itemcolorset];
	    CF.cur_input->header.dt_ptr->dt_Fstr->flags.has_colorset = True;
	  }
	  CF.cur_input->header.dt_ptr->dt_Fstr->str = CF.cur_input->input.value;
	  CF.cur_input->header.dt_ptr->dt_Fstr->x   = BOX_SPC + TEXT_SPC;
	  CF.cur_input->header.dt_ptr->dt_Fstr->y   = BOX_SPC + TEXT_SPC
	    + CF.cur_input->header.dt_ptr->dt_Ffont->ascent;
	  CF.cur_input->header.dt_ptr->dt_Fstr->len = len;
	  FlocaleDrawString(dpy,
			    CF.cur_input->header.dt_ptr->dt_Ffont,
			    CF.cur_input->header.dt_ptr->dt_Fstr,
			    FWS_HAVE_LENGTH);
	  x = BOX_SPC + TEXT_SPC +
		  FlocaleTextWidth(CF.cur_input->header.dt_ptr->dt_Ffont,
				   CF.cur_input->input.value,CF.abs_cursor)
		  - 1;
	  dy = CF.cur_input->header.size_y - 1;
	  XDrawLine(dpy, CF.cur_input->header.win,
		    CF.cur_input->header.dt_ptr->dt_item_GC,
		    x, BOX_SPC, x, dy - BOX_SPC);
	  myfprintf((stderr,"Line %d/%d - %d/%d (char)\n",
		     x, BOX_SPC, x, dy - BOX_SPC));
	}
      no_redraw:
	break;  /* end of case KeyPress */
      }  /* end of switch (event.type) */
      continue;
    }  /* end of if (event.xany.window == CF.frame) */
    for (item = root_item_ptr; item != 0;
	 item = item->header.next) {    /* all items */
      if (event.xany.window == item->header.win) {
	switch (event.type) {
	case Expose:
	{
		int ex = event.xexpose.x;
		int ey = event.xexpose.y;
		int ex2 = event.xexpose.x + event.xexpose.width;
		int ey2 = event.xexpose.y + event.xexpose.height;
		while (FCheckTypedWindowEvent(
			dpy, item->header.win, Expose, &event))
		{
			ex = min(ex, event.xexpose.x);
			ey = min(ey, event.xexpose.y);
			ex2 = max(ex2, event.xexpose.x + event.xexpose.width);
			ey2 = max(ey2 , event.xexpose.y + event.xexpose.height);
		}
		event.xexpose.x = ex;
		event.xexpose.y = ey;
		event.xexpose.width = ex2 - ex;
		event.xexpose.height = ey2 - ey;
		RedrawItem(item, 0, &event);
	}
	break;
	case ButtonPress:
	  if (item->type == I_INPUT) {
	    old_item = CF.cur_input;
	    CF.cur_input = item;
	    RedrawItem(old_item, 1, NULL);
	    {
	      Bool done = False;

	      CF.abs_cursor = 0;
	      while(CF.abs_cursor <= item->input.size && !done)
	      {
		if (FlocaleTextWidth(item->header.dt_ptr->dt_Ffont,
				     item->input.value,
				     CF.abs_cursor) >=
		    event.xbutton.x - BOX_SPC - TEXT_SPC)
		{
		  done = True;
		  CF.abs_cursor--;
		}
		else
		{
		  CF.abs_cursor++;
		}
	      }
	    }
	    if (CF.abs_cursor < 0)
	      CF.abs_cursor = 0;
	    if (CF.abs_cursor > item->input.size)
	      CF.abs_cursor = item->input.size;
	    CF.rel_cursor = CF.abs_cursor + item->input.left;
	    if (CF.rel_cursor < 0)
	      CF.rel_cursor = 0;
	    if (CF.rel_cursor > item->input.n)
	      CF.rel_cursor = item->input.n;
	    if (CF.rel_cursor > 0 && CF.rel_cursor == item->input.left)
	      item->input.left--;
	    if (CF.rel_cursor < item->input.n &&
		CF.rel_cursor == item->input.left + item->input.size)
	      item->input.left++;
	    CF.abs_cursor = CF.rel_cursor - item->input.left;
	    if (event.xbutton.button == Button2) { /* if paste request */
	      process_paste_request (&event, item);
	    }
	    RedrawItem(item, 0, NULL);
	  }
	  if (item->type == I_CHOICE)
	    ToggleChoice(item);
	  if (item->type == I_BUTTON) {
	    RedrawItem(item, 1, NULL);    /* push button in */
	    if (CF.activate_on_press) {
	      usleep(MICRO_S_FOR_10MS);   /* make sure its visible */
	      RedrawItem(item, 0, NULL);  /* pop button out */
	      DoCommand(item);            /* execute the button command */
	    } else {
	      XGrabPointer(dpy, item->header.win,
			   False,         /* owner of events */
			   ButtonReleaseMask, /* events to report */
			   GrabModeAsync, /* keyboard mode */
			   GrabModeAsync, /* pointer mode */
			   None,          /* confine to */
			   /* I sort of like this, the hand points in
			      the other direction and the color is
			      reversed. I don't know what other GUIs do,
			      Java doesn't do anything, neither does anything
			      else I can find...dje */
			   CF.pointer[button_in_pointer],   /* cursor */
			   CurrentTime);
	    } /* end activate on press */
	  }
	  break;
	case ButtonRelease:
	  if (!CF.activate_on_press) {
	    RedrawItem(item, 0, NULL);
	    if (CF.grab_server && CF.server_grabbed) {
	      /* You have to regrab the pointer, or focus
		 can go to another window.
		 grab...
	      */
	      XGrabPointer(dpy, CF.frame, True, 0, GrabModeAsync, GrabModeAsync,
			   None, None, CurrentTime);
	      XFlush(dpy);
	    } else {
	      XUngrabPointer(dpy, CurrentTime);
	      XFlush(dpy);
	    }
	    if (event.xbutton.x >= 0 &&
		event.xbutton.x < item->header.size_x &&
		event.xbutton.y >= 0 &&
		event.xbutton.y < item->header.size_y) {
	      DoCommand(item);
	    }
	  }
	  break;
	}
      }
    }  /* end of for (i = 0) */
  }  /* while loop */
}
Example #4
0
void Download_findu_trail( /*@unused@*/ Widget w, /*@unused@*/ XtPointer clientData, /*@unused@*/ XtPointer callData) {
    static Widget pane, my_form, button_ok, button_cancel, call, sep;
    Atom delw;
    XmString x_str;


    if (!download_findu_dialog) {

begin_critical_section(&download_findu_dialog_lock, "track_gui.c:Download_findu_trail" );

        download_findu_dialog = XtVaCreatePopupShell(langcode("WPUPTSP007"),
                xmDialogShellWidgetClass, appshell,
                XmNdeleteResponse,XmDESTROY,
                XmNdefaultPosition, FALSE,
                XmNfontList, fontlist1,
                NULL);

        pane = XtVaCreateWidget("Download_findu_trail pane",
                xmPanedWindowWidgetClass, 
                download_findu_dialog,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                NULL);

        my_form =  XtVaCreateWidget("Download_findu_trail my_form",
                xmFormWidgetClass, 
                pane,
                XmNfractionBase, 2,
                XmNautoUnmanage, FALSE,
                XmNshadowThickness, 1,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                NULL);

        call = XtVaCreateManagedWidget(langcode("WPUPTSP008"),
                xmLabelWidgetClass, 
                my_form,
                XmNtopAttachment, XmATTACH_FORM,
                XmNtopOffset, 10,
                XmNbottomAttachment, XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_FORM,
                XmNleftOffset, 10,
                XmNrightAttachment, XmATTACH_NONE,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        download_trail_station_data = XtVaCreateManagedWidget("download_trail_station_data", 
                xmTextFieldWidgetClass, 
                my_form,
                XmNeditable,   TRUE,
                XmNcursorPositionVisible, TRUE,
                XmNsensitive, TRUE,
                XmNshadowThickness,    1,
                XmNcolumns, 15,
                XmNwidth, ((15*7)+2),
                XmNmaxLength, 15,
                XmNbackground, colors[0x0f],
                XmNtopAttachment,XmATTACH_FORM,
                XmNtopOffset, 5,
                XmNbottomAttachment,XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_WIDGET,
                XmNleftWidget, call,
                XmNleftOffset, 10,
                XmNrightAttachment,XmATTACH_NONE,
                XmNnavigationType, XmTAB_GROUP,
                XmNtraversalOn, TRUE,
                XmNfontList, fontlist1,
                NULL);

        x_str = XmStringCreateLocalized(langcode("WPUPTSP009"));
        posit_start_value = XtVaCreateManagedWidget("Start of Trail (hrs ago)", 
                xmScaleWidgetClass, 
                my_form,
                XmNtopAttachment,XmATTACH_WIDGET,
                XmNtopWidget, call,
                XmNtopOffset, 15,
                XmNbottomAttachment,XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_FORM,
                XmNleftOffset, 10,
                XmNrightAttachment,XmATTACH_NONE,
                XmNnavigationType, XmTAB_GROUP,
                XmNtraversalOn, TRUE,
                //XmNwidth, 190,
                XmNrightAttachment, XmATTACH_FORM,
                XmNrightOffset, 10,
                XmNsensitive, TRUE,
                XmNorientation, XmHORIZONTAL,
                XmNborderWidth, 1,
                XmNminimum, 1,
                XmNmaximum, MAX_FINDU_START_TIME,
                XmNshowValue, TRUE,
                XmNvalue, posit_start,
// Note:  Some versions of OpenMotif (distributed with Fedora,
// perhaps others) don't work properly with XtVaTypedArg() as used
// here, instead showing blank labels for the Scale widgets.
//                XtVaTypedArg, XmNtitleString, XmRString, langcode("WPUPTSP009"), 22,
                XmNtitleString, x_str,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);
        XmStringFree(x_str);

        x_str = XmStringCreateLocalized(langcode("WPUPTSP010"));
        posit_length_value = XtVaCreateManagedWidget("Length of trail (hrs)", 
                xmScaleWidgetClass, 
                my_form,
                XmNtopAttachment,XmATTACH_WIDGET,
                XmNtopWidget, posit_start_value,
                XmNtopOffset, 15,
                XmNbottomAttachment,XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_FORM,
                XmNleftOffset, 10,
                XmNrightAttachment,XmATTACH_NONE,
                XmNnavigationType, XmTAB_GROUP,
                XmNtraversalOn, TRUE,
                //XmNwidth, 190,
                XmNrightAttachment, XmATTACH_FORM,
                XmNrightOffset, 10,
                XmNsensitive, TRUE,
                XmNorientation, XmHORIZONTAL,
                XmNborderWidth, 1,
                XmNminimum, 1,
                XmNmaximum, MAX_FINDU_DURATION,
                XmNshowValue, TRUE,
                XmNvalue, posit_length,
// Note:  Some versions of OpenMotif (distributed with Fedora,
// perhaps others) don't work properly with XtVaTypedArg() as used
// here, instead showing blank labels for the Scale widgets.
//                XtVaTypedArg, XmNtitleString, XmRString, langcode("WPUPTSP010"), 19,
                XmNtitleString, x_str,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);
        XmStringFree(x_str);

        sep = XtVaCreateManagedWidget("Download_findu_trail sep", 
                xmSeparatorGadgetClass,
                my_form,
                XmNorientation, XmHORIZONTAL,
                XmNtopAttachment,XmATTACH_WIDGET,
                XmNtopWidget,posit_length_value,
                XmNtopOffset, 10,
                XmNbottomAttachment,XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_FORM,
                XmNrightAttachment,XmATTACH_FORM,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        button_ok = XtVaCreateManagedWidget(langcode("WPUPTSP007"),
                xmPushButtonGadgetClass, 
                my_form,
                XmNtopAttachment, XmATTACH_WIDGET,
                XmNtopWidget, sep,
                XmNtopOffset, 5,
                XmNbottomAttachment, XmATTACH_FORM,
                XmNbottomOffset, 5,
                XmNleftAttachment, XmATTACH_POSITION,
                XmNleftPosition, 0,
                XmNleftOffset, 5,
                XmNrightAttachment, XmATTACH_POSITION,
                XmNrightPosition, 1,
                XmNnavigationType, XmTAB_GROUP,
                XmNtraversalOn, TRUE,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);
        if (fetching_findu_trail_now)
            XtSetSensitive(button_ok, FALSE);

        button_cancel = XtVaCreateManagedWidget(langcode("UNIOP00002"),
                xmPushButtonGadgetClass, 
                my_form,
                XmNtopAttachment, XmATTACH_WIDGET,
                XmNtopWidget, sep,
                XmNtopOffset, 5,
                XmNbottomAttachment, XmATTACH_FORM,
                XmNbottomOffset, 5,
                XmNleftAttachment, XmATTACH_POSITION,
                XmNleftPosition, 1,
                XmNrightAttachment, XmATTACH_POSITION,
                XmNrightPosition, 2,
                XmNrightOffset, 5,
                XmNnavigationType, XmTAB_GROUP,
                XmNtraversalOn, TRUE,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        XtAddCallback(button_ok, XmNactivateCallback, Download_trail_now, download_findu_dialog);
        XtAddCallback(button_cancel, XmNactivateCallback, Download_trail_destroy_shell, download_findu_dialog);
        XtAddCallback(posit_start_value, XmNvalueChangedCallback, Reset_posit_length_max, download_findu_dialog);

        pos_dialog(download_findu_dialog);

        delw = XmInternAtom(XtDisplay(download_findu_dialog),"WM_DELETE_WINDOW", FALSE);
        XmAddWMProtocolCallback(download_findu_dialog, delw, Download_trail_destroy_shell, (XtPointer)download_findu_dialog);

        XmTextFieldSetString(download_trail_station_data,download_trail_station_call);

        XtManageChild(my_form);
        XtManageChild(pane);

end_critical_section(&download_findu_dialog_lock, "track_gui.c:Download_trail" );

        XtPopup(download_findu_dialog,XtGrabNone);
        fix_dialog_size(download_findu_dialog);

        // Move focus to the Cancel button.  This appears to highlight the
        // button fine, but we're not able to hit the <Enter> key to
        // have that default function happen.  Note:  We _can_ hit the
        // <SPACE> key, and that activates the option.
//        XmUpdateDisplay(download_findu_dialog);
        XmProcessTraversal(button_cancel, XmTRAVERSE_CURRENT);

    } else
        (void)XRaiseWindow(XtDisplay(download_findu_dialog), XtWindow(download_findu_dialog));
}
Example #5
0
static void xskin_jobs( int pipe_in ) {
  XEvent e;
  int x,y;
  int window_x,window_y;
  int fspe=0;
  int pr=-1;
  int z;
  int p;
  int master_volume=0;
  char file_name[1024], tmp[1024];

  int last_puttext_time;
  int last_window_x=-1, last_window_y=-1;

  int max_files;
  int i;
  fd_set fds;
  static struct timeval tv;

  Window t_w;
  unsigned int t_width, t_height, t_border, t_depth;

  xskin_pipe_write( "READY" );

  shmid = shmget( IPC_PRIVATE, sizeof(char)*SPE_W, IPC_CREAT|0600 );
  if ( shmid<0 ) xskin_pipe_write( "ERROR" );
  else {
    sprintf( local_buf, "%d", shmid );
    xskin_pipe_write( local_buf );
    speana_buf = (unsigned char *)shmat( shmid, 0, 0 );
  }

  xskin_pipe_read( local_buf, sizeof(local_buf) );
  max_files = atoi( local_buf );
  for ( i=0 ; i<max_files ; i++ ) {
    xskin_pipe_read( local_buf, sizeof(local_buf) );
  }

  z=1;
  last_puttext_time=0;
  last_current_time=0;

  XGetGeometry( xskin_d, xskin_w, &t_w,
		&window_x, &window_y,
		&t_width, &t_height, &t_border, &t_depth );

  while( z ) {

    XFlush( xskin_d );

    FD_ZERO( &fds );
    FD_SET( pipe_in, &fds );
    tv.tv_sec=0;
    tv.tv_usec=20000L; /* 20 msec */
    i=select( pipe_in+1, &fds, NULL, NULL, &tv );

    if ( i!=0 ) {
      xskin_pipe_read( local_buf, sizeof(local_buf) );
      switch (local_buf[0]) {

      case 'A': /* total time */
	total_time=atoi( local_buf+2 );
	last_current_time=0;
	last_puttext_time=0;
	break;
	
      case 'T': /* current time */
	{
	  int min,sec;
	  sscanf( local_buf+2, "%02d:%02d", &min, &sec );
	  i=min*60+sec;
	  if ( fremain==1 ) {
	    sec =total_time-i;
	    min =sec/60;
	    sec-=min*60;
	  }
	  if ( i != last_current_time ) {
	    ts_putnum( MIN_H_X, MIN_H_Y, min/10 );
	    ts_putnum( MIN_L_X, MIN_L_Y, min%10 );
	    ts_putnum( SEC_H_X, SEC_H_Y, sec/10 );
	    ts_putnum( SEC_L_X, SEC_L_Y, sec%10 );
	    p=100*i/total_time;
	    play_val=ts_pos( OFF, -p );
	    last_current_time=i;

	    if ( last_current_time - last_puttext_time == 3 ) { /* 3 sec */
	      sprintf( tmp, "%s [%02d:%02d]",
		       file_name, total_time/60, total_time%60 );
	      ts_puttext( MESSAGE_X, MESSAGE_Y, tmp );
	    }
	  }
	}
      break;

      case 'L': /* lylics/message */
	ts_puttext( MESSAGE_X, MESSAGE_Y, local_buf+2 );
	last_puttext_time=last_current_time;
	break;

      case 'F': /* filename */
	strncpy( file_name, local_buf+2, 1023 );
	file_name[1023]=0;
	break;

      case 'O': /* off the play button */
	fplay=0;
	ts_play(OFF);
	ts_spectrum(fspe, NULL); /* erase spectrums */
	break;

      case 'V': /* master volume */
	master_volume=atoi( local_buf+2 );
	p=100*((master_volume<200)?master_volume:200)/200; /* max:200% */
	vol_val=ts_volume( OFF, -p );
	break;

      case 'Q': /* quit */
	z=1;
	break;

      case 'W': /* wave form */
	ts_spectrum(fspe, speana_buf);
	break;

      default:
	break;
      }
    }

    if ( XPending( xskin_d )==0 ) continue;
    XNextEvent( xskin_d, &e );

    switch ( e.type ) {
      /*
    case KeyPress:
      z=0;
      break;
      */
   
    case Expose:
      repaint();
      break;

    case EnterNotify:
      {
	Cursor cs;
	ts_titlebar(ON);
	cs = XCreateFontCursor( xskin_d, XC_top_left_arrow );
	XDefineCursor( xskin_d, xskin_w, cs );
      }
      break;

    case LeaveNotify:
      ts_titlebar(OFF);
      XUndefineCursor( xskin_d, xskin_w );
      break;

    case MotionNotify:
      while( XCheckMaskEvent( xskin_d, Button1MotionMask, &e ) ) {
	XNextEvent( xskin_d, &e );
      }
      x = e.xbutton.x;
      y = e.xbutton.y;
      switch( pr ) {
	
	/*
      case TS_POS:
	play_val=ts_pos( ON, x );break;
	*/
      case TS_VOLUME:
	vol_val=ts_volume( ON, x );
	i=master_volume;
	master_volume=200*vol_val/100;
	sprintf( local_buf, "V %d", master_volume-i );
	xskin_pipe_write( local_buf );

	sprintf( tmp, " volume: %d%%", vol_val );
	ts_puttext( MESSAGE_X, MESSAGE_Y, tmp );
	last_puttext_time=last_current_time;
	break;
	/*
      case TS_PAN:
	pan_val=ts_pan( ON, x );break;
	*/
	
      default:
	if ( x != last_window_x || y != last_window_y ) {
	  window_x += x-last_window_x;
	  window_y += y-last_window_y;
	  XMoveWindow( xskin_d, xskin_w,
		       window_x, window_y );
	}
	break;
      }
      break;

    case ButtonPress:
      x = e.xbutton.x;
      y = e.xbutton.y;
      last_window_x=x;
      last_window_y=y;

             if ( ISIN( x, y,EXITBUTTON_DX,EXITBUTTON_DY,
			EXITBUTTON_W,EXITBUTTON_H ) ) {
        ts_exitbutton(ON);pr=TS_EXITBUTTON;

      } else if ( ISIN( x, y, PREV_DX, PREV_DY, PREV_W, PREV_H ) ) {
	ts_prev(ON);pr=TS_PREV;
      } else if ( ISIN( x, y, PLAY_DX, PLAY_DY, PLAY_W, PLAY_H ) ) {
	ts_play(ON);pr=TS_PLAY;
      } else if ( ISIN( x, y, PAUSE_DX, PAUSE_DY, PAUSE_W, PAUSE_H ) ) {
	ts_pause(ON);pr=TS_PAUSE;
      } else if ( ISIN( x, y, STOP_DX, STOP_DY, STOP_W, STOP_H ) ) {
	ts_stop(ON);pr=TS_STOP;
      } else if ( ISIN( x, y, NEXT_DX, NEXT_DY, NEXT_W, NEXT_H ) ) {
	ts_next(ON);pr=TS_NEXT;
      } else if ( ISIN( x, y, EJECT_DX, EJECT_DY, EJECT_W, EJECT_H ) ) {
	ts_eject(ON);pr=TS_EJECT;

      } else if ( ISIN( x, y,164, 89, 47, 15 ) ) {  /* shuffle */
	if ( fshuf==0 ) {
	  ts_shuf(OFFON);pr=TS_SHUFON;
	} else { 
	  ts_shuf(ONOFF);pr=TS_SHUFOFF;
	}
      } else if ( ISIN( x, y,210, 89, 28, 15 ) ) {  /* repeat */
	if ( frep==0 ) {
	  ts_rep(OFFON);pr=TS_REPON;
	} else {
	  ts_rep(ONOFF);pr=TS_REPOFF;
	}
      } else if ( ISIN( x, y,219, 58, 23, 12 ) ) {  /* equalizer */
	if ( fequ==0 ) {
	  ts_equ(OFFON);pr=TS_EQUON;
	} else {
	  ts_equ(ONOFF);pr=TS_EQUOFF;
	}
      } else if ( ISIN( x, y,242, 58, 23, 12 ) ) {  /* playlist */
	if ( fpll==0 ) {
	  ts_plist(OFFON);pr=TS_PLISTON;
	} else {
	  ts_plist(ONOFF);pr=TS_PLISTOFF;
	}

      } else if ( ISIN( x, y, MENUBUTTON_DX, MENUBUTTON_DY,
			MENUBUTTON_W, MENUBUTTON_H ) ) {
	ts_menubutton(ON);pr=TS_MENUBUTTON;
      } else if ( ISIN( x, y, ICONBUTTON_DX, ICONBUTTON_DY,
			ICONBUTTON_W, ICONBUTTON_H ) ) {
	ts_iconbutton(ON);pr=TS_ICONBUTTON;
      } else if ( ISIN( x, y, MINIBUTTON_DX, MINIBUTTON_DY,
			MINIBUTTON_W, MINIBUTTON_H ) ) {
	ts_minibutton(ON);pr=TS_MINIBUTTON;

	/*
      }	else if ( ISIN( x, y,POS_MIN_DX+(POS_MAX_DX-POS_MIN_DX)*play_val/100,
			POS_DY, POS_W, POS_H ) ) {
	ts_pos( ON, -play_val );pr=TS_POS;
	*/
      } else if ( ISIN( x, y,VOL_MIN_DX+(VOL_MAX_DX-VOL_MIN_DX)*vol_val/100,
			VOL_DY, VOL_W, VOL_H ) ) {
	ts_volume( ON, -vol_val );pr=TS_VOLUME;
	sprintf( tmp, " volume: %d%%", vol_val );
	ts_puttext( MESSAGE_X, MESSAGE_Y, tmp );
	last_puttext_time=last_current_time;

	/*
      } else if ( ISIN( x, y,PAN_MIN_DX+(PAN_MAX_DX-PAN_MIN_DX)*pan_val/100,
			PAN_DY, PAN_W, PAN_H ) ) {
	ts_pan( ON, -pan_val );pr=TS_PAN;
	*/

      } else if ( ISIN( x, y, MIN_H_X, MIN_H_Y,
			SEC_L_X+NUM_W-MIN_H_X, NUM_H ) ) {
	int min,sec;
	fremain=(fremain==0)?1:0;
	sec=(fremain==0)?last_current_time:total_time-last_current_time;
	min =sec/60;
	sec-=min*60;
	ts_putnum( MIN_H_X, MIN_H_Y, min/10 );
	ts_putnum( MIN_L_X, MIN_L_Y, min%10 );
	ts_putnum( SEC_H_X, SEC_H_Y, sec/10 );
	ts_putnum( SEC_L_X, SEC_L_Y, sec%10 );

      } else if ( ISIN( x, y, SPE_SX, SPE_SY, SPE_W, SPE_H ) ) {
	pr=TS_SPECTRUM;
      } else {
	XRaiseWindow( xskin_d, xskin_w );
      }
	     break;  

    case ButtonRelease:

      last_window_x = -1;
      last_window_y = -1;

      switch( pr ) {

      case TS_EXITBUTTON:
	ts_exitbutton(OFF);
	xskin_pipe_write("Q");
	z=0;break;

      case TS_PREV:
	ts_prev(OFF);
	ts_spectrum( fspe, NULL );
	xskin_pipe_write("B");
	break;
      case TS_PLAY:
	xskin_pipe_write("P");
	fplay=1;
	pauseOff();
	ts_play(OFF);ts_pause(OFF);
	ts_pstate( PSTATE_PLAY );
	break;
      case TS_PAUSE:
	ts_pause(OFF);
	if ( fplay ==1 ) {
	  if ( fpause==0 ) {
	    ts_pstate( PSTATE_PAUSE );
	    ts_spectrum( fspe, NULL );
	    pauseOn();
	  } else {
	    ts_pstate( PSTATE_PLAY );
	    pauseOff();
	  }
	}
	break;
      case TS_STOP:
	pauseOff();
	fplay=0;
	ts_pause(OFF);ts_play(OFF);ts_stop(OFF);
	ts_pstate( PSTATE_STOP );
	ts_spectrum( fspe, NULL );
	xskin_pipe_write("S");
	break;
      case TS_NEXT:
	ts_next(OFF);
	ts_spectrum( fspe, NULL );
	xskin_pipe_write("N");
	break;
      case TS_EJECT:
	ts_eject(OFF);break;

      case TS_SHUFON:
	ts_shuf(ON);fshuf=1;
	fplay=1;
	pauseOff();
	ts_pstate( PSTATE_PLAY );
	xskin_pipe_write("D 1");
	break;
      case TS_SHUFOFF:
	ts_shuf(OFF);fshuf=0;
	fplay=0;
	pauseOff();
	ts_pstate( PSTATE_STOP );
	ts_spectrum( fspe, NULL );
	xskin_pipe_write("D 2");
	break;
      case TS_REPON:
	ts_rep(ON);frep=1;
	xskin_pipe_write("R 1");
	break;
      case TS_REPOFF:
	ts_rep(OFF);frep=0;
	xskin_pipe_write("R 0");
	break;

      case TS_EQUON:
	ts_equ(ON);fequ=1;break;
      case TS_EQUOFF:
	ts_equ(OFF);fequ=0;break;

      case TS_PLISTON:
	ts_plist(ON);fpll=1;break;
      case TS_PLISTOFF:
	ts_plist(OFF);fpll=0;break;

      case TS_MENUBUTTON:
	ts_menubutton(OFF);break;
      case TS_ICONBUTTON:
	ts_iconbutton(OFF);break;
      case TS_MINIBUTTON:
	ts_minibutton(OFF);break;

	/*
      case TS_POS:
	ts_pos( OFF, -play_val );break;
	*/
      case TS_VOLUME:
	ts_volume( OFF, -vol_val );break;
	/*
      case TS_PAN:
	ts_pan( OFF, -pan_val );break;
	*/

      case TS_SPECTRUM:
#ifdef SUPPORT_SOUNDSPEC
	fspe = (fspe+1)%3;
	if ( fspe==1 ) xskin_pipe_write("W");      /* on */
	else if ( fspe==0 ) {
	  xskin_pipe_write("W"); /* off */
	  ts_spectrum(0,speana_buf);
	}
#endif /* SUPPORT_SOUNDSPEC */
	break;

      default:
	break;
      }
      pr=-1;
      break;

    default:
      break;
    }
  }

  return;
}
Example #6
0
File: nenu.c Project: mytchel/nenu
int main(int argc, char *argv[]) {
	XEvent ev;
	int i, time, pending;
	
	for (i = 1; i < argc; i++) {
		if (strcmp(argv[i], "--pos") == 0) {
			x = atoi(strsep(&argv[++i], ","));
			y = atoi(argv[i]);
		} else if (strcmp(argv[i], "--abs") == 0) {
			absolute_position = 1;
		} else if (strcmp(argv[i], "--fg") == 0) {
			strcpy(fg_name, argv[++i]);
		} else if (strcmp(argv[i], "--bg") == 0) {
			strcpy(bg_name, argv[++i]);
		} else if (strcmp(argv[i], "--fn") == 0) {
			strcpy(font_str, argv[++i]);
		} else if (argv[i][0] == '-') {
			switch (argv[i][1])
			{
			case 'h':
				usage();
				exit(EXIT_SUCCESS);
			case 'o': exit_on_one = 1; break;
			case 'f': first_on_exit = 1; break;
			case 't': text_input = 0; break;
			case 'q': print_on_exit = 0; break;
			case 'n': read_options = 0; break;
			case 'g': grab = 0; break;
			default:
				fprintf(stderr, "Unknown option: %s\n",
					argv[i]);
				usage();
				exit(EXIT_FAILURE);
			}
		} else {
			strcpy(prompt, argv[i]);
		}
	}

	setup();

	if (read_options) read_input();

	XMapWindow(display, win);
	set_position();
	grab_keyboard_pointer();

	for(;;) {
		XNextEvent(display, &ev);
		switch (ev.type) {
		case KeyPress:
			handle_key(ev.xkey);
			render();
			break;
		case ButtonRelease:
			handle_button(ev.xbutton);
			render();
			break;
		case Expose:
			XRaiseWindow(display, win);
			render();
			break;
		}
	}

	clean_resources();
	exit(EXIT_FAILURE);
}
Example #7
0
int
XMenuActivate(
    register Display *display,		/* Display to put menu on. */
    register XMenu *menu,		/* Menu to activate. */
    int *p_num,				/* Pane number selected. */
    int *s_num,				/* Selection number selected. */
    int x_pos,				/* X coordinate of menu position. */
    int y_pos,				/* Y coordinate of menu position. */
    unsigned int event_mask,		/* Mouse button event mask. */
    char **data,			/* Pointer to return data value. */
    void (*help_callback) (char const *, int, int)) /* Help callback.  */
{
    int status;				/* X routine call status. */
    int orig_x;				/* Upper left menu origin X coord. */
    int orig_y;				/* Upper left menu origin Y coord. */
    int ret_val;			/* Return value. */

    register XMPane *p_ptr;		/* Current XMPane. */
    register XMPane *event_xmp;		/* Event XMPane pointer. */
    register XMPane *cur_p;		/* Current pane. */
    register XMSelect *cur_s;		/* Current selection. */
    XMWindow *event_xmw;		/* Event XMWindow pointer. */
    XEvent event;			/* X input event. */
    XEvent peek_event;			/* X input peek ahead event. */

    Bool selection = False;		/* Selection has been made. */
    Bool forward = True;		/* Moving forward in the pane list. */

    Window root, child;
    int root_x, root_y, win_x, win_y;
    unsigned int mask;
    KeySym keysym;

    /*
     * Define and allocate a foreign event queue to hold events
     * that don't belong to XMenu.  These events are later restored
     * to the X event queue.
     */
    typedef struct _xmeventque {
	XEvent event;
	struct _xmeventque *next;
    } XMEventQue;

    XMEventQue *feq = NULL;    		/* Foreign event queue. */
    XMEventQue *feq_tmp;		/* Foreign event queue temporary. */

    /*
     * If there are no panes in the menu then return failure
     * because the menu is not initialized.
     */
    if (menu->p_count == 0) {
	_XMErrorCode = XME_NOT_INIT;
	return(XM_FAILURE);
    }

    /*
     * Find the desired current pane.
     */
    cur_p = _XMGetPanePtr(menu, *p_num);
    if (cur_p == NULL) {
	return(XM_FAILURE);
    }
    cur_p->activated = cur_p->active;

    /*
     * Find the desired current selection.
     * If the current selection index is out of range a null current selection
     * will be assumed and the cursor will be placed in the current pane
     * header.
     */
    cur_s = _XMGetSelectionPtr(cur_p, *s_num);

    /*
     * Compute origin of menu so that cursor is in
     * Correct pane and selection.
     */
    _XMTransToOrigin(display,
		     menu,
		     cur_p, cur_s,
		     x_pos, y_pos,
		     &orig_x, &orig_y);
    menu->x_pos = orig_x;	/* Store X and Y coords of menu. */
    menu->y_pos = orig_y;

    if (XMenuRecompute(display, menu) == XM_FAILURE) {
	return(XM_FAILURE);
    }

    /*
     * Flush the window creation queue.
     * This batches all window creates since lazy evaluation
     * is more efficient than individual evaluation.
     * This routine also does an XFlush().
     */
    if (_XMWinQueFlush(display, menu, cur_p, cur_s) == _FAILURE) {
	return(XM_FAILURE);
    }

    /*
     * Make sure windows are in correct order (in case we were passed
     * an already created menu in incorrect order.)
     */
    for(p_ptr = menu->p_list->next; p_ptr != cur_p; p_ptr = p_ptr->next)
	XRaiseWindow(display, p_ptr->window);
    for(p_ptr = menu->p_list->prev; p_ptr != cur_p->prev; p_ptr = p_ptr->prev)
	XRaiseWindow(display, p_ptr->window);

    /*
     * Make sure all selection windows are mapped.
     */
    for (
	p_ptr = menu->p_list->next;
	p_ptr != menu->p_list;
	p_ptr = p_ptr->next
    ){
	XMapSubwindows(display, p_ptr->window);
    }

    /*
     * Synchronize the X buffers and the event queue.
     * From here on, all events in the queue that don't belong to
     * XMenu are sent back to the application via an application
     * provided event handler or discarded if the application has
     * not provided an event handler.
     */
    XSync(display, 0);

    /*
     * Grab the mouse for menu input.
     */

    status = XGrabPointer(
			  display,
			  menu->parent,
			  True,
			  event_mask,
			  GrabModeAsync,
			  GrabModeAsync,
			  None,
			  menu->mouse_cursor,
			  CurrentTime
			  );
    if (status == Success && x_menu_grab_keyboard)
      {
        status = XGrabKeyboard (display,
                                menu->parent,
                                False,
                                GrabModeAsync,
                                GrabModeAsync,
                                CurrentTime);
        if (status != Success)
          XUngrabPointer(display, CurrentTime);
      }

    if (status == _X_FAILURE) {
	_XMErrorCode = XME_GRAB_MOUSE;
	return(XM_FAILURE);
    }

    /*
     * Map the menu panes.
     */
    XMapWindow(display, cur_p->window);
    for (p_ptr = menu->p_list->next;
	 p_ptr != cur_p;
	 p_ptr = p_ptr->next)
      XMapWindow(display, p_ptr->window);
    for (p_ptr = cur_p->next;
	 p_ptr != menu->p_list;
	 p_ptr = p_ptr->next)
      XMapWindow(display, p_ptr->window);

    XRaiseWindow(display, cur_p->window);	/* Make sure current */
						/* pane is on top. */

    cur_s = NULL;			/* Clear current selection. */

    /*
     * Begin event processing loop.
     */
    while (1) {
        if (wait_func) (*wait_func) (wait_data);
	XNextEvent(display, &event);	/* Get next event. */
	switch (event.type) {		/* Dispatch on the event type. */
    case Expose:
	    event_xmp = (XMPane *)XLookUpAssoc(display,
					       menu->assoc_tab,
					       event.xexpose.window);
	    if (event_xmp == NULL) {
		/*
		 * If AEQ mode is enabled then queue the event.
		 */
		if (menu->aeq) {
		    feq_tmp = (XMEventQue *)malloc(sizeof(XMEventQue));
		    if (feq_tmp == NULL) {
			_XMErrorCode = XME_CALLOC;
			return(XM_FAILURE);
		    }
		    feq_tmp->event = event;
		    feq_tmp->next = feq;
		    feq = feq_tmp;
		}
		else if (_XMEventHandler) (*_XMEventHandler)(&event);
		break;
	    }
	    if (event_xmp->activated) {
		XSetWindowBackground(display,
				     event_xmp->window,
				     menu->bkgnd_color);
	    }
	    else {
		XSetWindowBackgroundPixmap(display,
					   event_xmp->window,
					   menu->inact_pixmap);
	    }
	    _XMRefreshPane(display, menu, event_xmp);
	    break;
    case EnterNotify:
	    /*
	     * First wait a small period of time, and see
	     * if another EnterNotify event follows hard on the
	     * heels of this one. i.e., the user is simply
	     * "passing through". If so, ignore this one.
	     */

	    event_xmw = (XMWindow *)XLookUpAssoc(display,
						 menu->assoc_tab,
						 event.xcrossing.window);
	    if (event_xmw == NULL) break;
	    if (event_xmw->type == SELECTION) {
		/*
		 * We have entered a selection.
		 */
		/* if (XPending(display) == 0) usleep(150000); */
		if (XPending(display) != 0) {
		    XPeekEvent(display, &peek_event);
		    if(peek_event.type == LeaveNotify) {
			break;
		    }
		}
		cur_s = (XMSelect *)event_xmw;
		help_callback (cur_s->help_string,
			       cur_p->serial, cur_s->serial);

		/*
		 * If the pane we are in is active and the
		 * selection entered is active then activate
		 * the selection.
		 */
		if (cur_p->active && cur_s->active > 0) {
		    cur_s->activated = 1;
		    _XMRefreshSelection(display, menu, cur_s);
		}
	    }
	    else {
		/*
		 * We have entered a pane.
		 */
		/* if (XPending(display) == 0) usleep(150000); */
		if (XPending(display) != 0) {
		    XPeekEvent(display, &peek_event);
		    if (peek_event.type == EnterNotify) break;
		}
		XQueryPointer(display,
			      menu->parent,
			      &root, &child,
			      &root_x, &root_y,
			      &win_x, &win_y,
			      &mask);
		event_xmp = (XMPane *)XLookUpAssoc(display,
						   menu->assoc_tab,
						   child);
		if (event_xmp == NULL) break;
		if (event_xmp == cur_p) break;
		if (event_xmp->serial > cur_p->serial) forward = True;
		else forward = False;
		p_ptr = cur_p;
		while (p_ptr != event_xmp) {
		    if (forward) p_ptr = p_ptr->next;
		    else p_ptr = p_ptr->prev;
		    XRaiseWindow(display, p_ptr->window);
		}
		if (cur_p->activated) {
		    cur_p->activated = False;
		    XSetWindowBackgroundPixmap(display,
					       cur_p->window,
					       menu->inact_pixmap);
		    _XMRefreshPane(display, menu, cur_p);
		}
		if (event_xmp->active) event_xmp->activated = True;
#if 1
		/*
		 * i suspect the we don't get an EXPOSE event when backing
		 * store is enabled; the menu windows content is probably
		 * not drawn in when it should be in that case.
		 * in that case, this is probably an ugly fix!
		 * i hope someone more familiar with this code would
		 * take it from here.  -- [email protected].
		 */
		XSetWindowBackground(display,
				     event_xmp->window,
				     menu->bkgnd_color);
		_XMRefreshPane(display, menu, event_xmp);
#endif
		cur_p = event_xmp;
	    }
	    break;
    case LeaveNotify:
	    event_xmw = (XMWindow *)XLookUpAssoc(
						 display,
						 menu->assoc_tab,
						 event.xcrossing.window
						 );
	    if (event_xmw == NULL) break;
	    if(cur_s == NULL) break;

	    /*
	     * If the current selection was activated then
	     * deactivate it.
	     */
	    if (cur_s->activated) {
		cur_s->activated = False;
		_XMRefreshSelection(display, menu, cur_s);
	    }
	    cur_s = NULL;
	    break;

    case ButtonPress:
    case ButtonRelease:
		*p_num = cur_p->serial;
		/*
		 * Check to see if there is a current selection.
		 */
		if (cur_s != NULL) {
		    /*
		     * Set the selection number to the current selection.
		     */
		    *s_num = cur_s->serial;
		    /*
		     * If the current selection was activated then
		     * we have a valid selection otherwise we have
		     * an inactive selection.
		     */
		    if (cur_s->activated) {
			*data = cur_s->data;
			ret_val = XM_SUCCESS;
		    }
		    else {
			ret_val = XM_IA_SELECT;
		    }
		}
		else {
		    /*
		     * No selection was current.
		     */
		    ret_val = XM_NO_SELECT;
		}
		selection = True;
		break;
        case KeyPress:
        case KeyRelease:
                keysym = XLookupKeysym (&event.xkey, 0);

                /* Pop down on C-g and Escape.  */
                if ((keysym == XK_g && (event.xkey.state & ControlMask) != 0)
                    || keysym == XK_Escape) /* Any escape, ignore modifiers.  */
                  {
                    ret_val = XM_NO_SELECT;
                    selection = True;
                  }
               break;
	    default:
		/*
		 * If AEQ mode is enabled then queue the event.
		 */
		if (menu->aeq) {
		    feq_tmp = (XMEventQue *)malloc(sizeof(XMEventQue));
		    if (feq_tmp == NULL) {
			_XMErrorCode = XME_CALLOC;
			return(XM_FAILURE);
		    }
		    feq_tmp->event = event;
		    feq_tmp->next = feq;
		    feq = feq_tmp;
		}
		else if (_XMEventHandler) (*_XMEventHandler)(&event);
	}
	/*
	 * If a selection has been made, break out of the event loop.
	 */
	if (selection == True) break;
    }

    /*
     * Unmap the menu.
     */
    for ( p_ptr = menu->p_list->next;
	 p_ptr != menu->p_list;
	 p_ptr = p_ptr->next)
      {
	  XUnmapWindow(display, p_ptr->window);
      }

    /*
     * Ungrab the mouse.
     */
    XUngrabPointer(display, CurrentTime);
    XUngrabKeyboard(display, CurrentTime);

    /*
     * Restore bits under where the menu was if we managed
     * to save them and free the pixmap.
     */

    /*
     * If there is a current selection deactivate it.
     */
    if (cur_s != NULL) cur_s->activated = 0;

    /*
     * Deactivate the current pane.
     */
    cur_p->activated = 0;
    XSetWindowBackgroundPixmap(display, cur_p->window, menu->inact_pixmap);

    /*
     * Synchronize the X buffers and the X event queue.
     */
    XSync(display, 0);

    /*
     * Dispatch any events remaining on the queue.
     */
    while (QLength(display)) {
	/*
	 * Fetch the next event.
	 */
	XNextEvent(display, &event);

	/*
	 * Discard any events left on the queue that belong to XMenu.
	 * All others are held and then returned to the event queue.
	 */
	switch (event.type) {
	    case Expose:
	    case EnterNotify:
	    case LeaveNotify:
	    case ButtonPress:
	    case ButtonRelease:
		/*
		 * Does this event belong to one of XMenu's windows?
		 * If so, discard it and process the next event.
		 * If not fall through and treat it as a foreign event.
		 */
		event_xmp = (XMPane *)XLookUpAssoc(
						   display,
						   menu->assoc_tab,
						   event.xbutton.window
						   );
		if (event_xmp != NULL) continue;
	    default:
		/*
		 * This is a foreign event.
		 * Queue it for later return to the X event queue.
		 */
		feq_tmp = (XMEventQue *)malloc(sizeof(XMEventQue));
		if (feq_tmp == NULL) {
		    _XMErrorCode = XME_CALLOC;
		    return(XM_FAILURE);
		}
		feq_tmp->event = event;
		feq_tmp->next = feq;
		feq = feq_tmp;
	    }
    }
    /*
     * Return any foreign events that were queued to the X event queue.
     */
    while (feq != NULL) {
	feq_tmp = feq;
	XPutBackEvent(display, &feq_tmp->event);
	feq = feq_tmp->next;
	free((char *)feq_tmp);
    }

    wait_func = 0;

    /*
     * Return successfully.
     */
    _XMErrorCode = XME_NO_ERROR;
    return(ret_val);

}
Example #8
0
/* Called for "Select by time..." button */
static int timestep_cb()
{
   XMapWindow( dpy_i, timewin );
   XRaiseWindow( dpy_i, timewin );
   return 0;
}
Example #9
0
/* Called for "Select by variable..." button */
static int variable_cb()
{
   XMapWindow( dpy_i, varwin );
   XRaiseWindow( dpy_i, varwin );
   return 0;
}
Example #10
0
File: main.c Project: braneed/scrot
/* get geometry of window and use that */
int
scrot_get_geometry(Window target,
                   Window *client_window,
                   int *rx, 
                   int *ry, 
                   int *rw, 
                   int *rh)
{
  Window child;
  XWindowAttributes attr;
  int stat;

  /* Get window manager frame and detect application window     */
  /* from pointed window.                                       */
  if (target != root) {
    int x;
    unsigned int d;
    int status;
    
    status = XGetGeometry(disp, target, &root, &x, &x, &d, &d, &d, &d);
    if (status != 0) {
      Window rt, *children, parent;
      
      /* Find toplevel window.                                  */
      /* It will have coordinates of window, that we look for   */
      /* But it may be completely different window (it depends  */
      /* on window manager).                                    */
      for (;;) {
        status = XQueryTree(disp, target, &rt, &parent, &children, &d);
        if (status && (children != None))
          XFree((char *) children);
        if (!status || (parent == None) || (parent == rt))
          break;
        target = parent;
      }

      /* Get client window. */
      if (opt.border)
      {
        *client_window = scrot_get_client_window(disp, target);
        target = scrot_get_net_frame_window(disp, target);
      }
      else
      {
        target = scrot_get_client_window(disp, target);
        *client_window = target;
      }

      XRaiseWindow(disp, target);
      XSetInputFocus(disp, target, RevertToParent, CurrentTime);
    }
  }
  stat = XGetWindowAttributes(disp, target, &attr);
  if ((stat == False) || (attr.map_state != IsViewable))
    return 0;
  *rw = attr.width;
  *rh = attr.height;
  XTranslateCoordinates(disp, target, root, 0, 0, rx, ry, &child);

  // additional border for shadows:
  // FIXME apply only if grabbing transparent screenshot
  // and not maximised nor fullscreen
  if(opt.alpha)
  {
    *rx -= 20;
    *ry -= 20;
    *rw += 40;
    *rh += 40;
  }

  return 1;
}
// Open the X window to sample from
bool InputWindowXWin::openLocalWindow()
{
   int i;

   mXDisplay = XOpenDisplay(mXDisplayString.c_str());    // Open display on given XDisplay
   if (NULL == mXDisplay)
   {
      vprDEBUG(vprDBG_ERROR, vprDBG_CRITICAL_LVL)
         <<  clrOutNORM(clrRED, "ERROR")
         << ": [gadget::InputWindowXWin::openTheWindow()] "
         << "Failed to open display '" << mXDisplayString << "'" << std::endl
         << vprDEBUG_FLUSH;
      return 0;
   }

   mScreen = DefaultScreen(mXDisplay);

   XVisualInfo vTemplate, *vis_infos;
   long vMask = VisualScreenMask;
   vTemplate.screen = mScreen;
   int nVisuals;

   vis_infos = XGetVisualInfo(mXDisplay, vMask, &vTemplate, &nVisuals);

   // Verify that we got at least one visual from XGetVisualInfo(3).
   if ( vis_infos != NULL && nVisuals >= 1 )
   {
      XVisualInfo* p_visinfo;

      // Try to find a visual with color depth of at least 8 bits.  Having
      // such a visual ensures that the input windows at least have a
      // black background.
      for ( i = 0, p_visinfo = vis_infos; i < nVisuals; i++, p_visinfo++ )
      {
         if ( p_visinfo->depth >= 8 )
         {
            mVisual = p_visinfo;
            break;
         }
      }

      // If we couldn't find a visual with at least 8-bit color, just use the
      // first one in the list.
      if ( i == nVisuals )
      {
          mVisual = vis_infos;
      }
   }
   // If we didn't get a matching visual, we're in trouble.
   else
   {
      vprDEBUG(vprDBG_ERROR,vprDBG_CRITICAL_LVL)
         <<  clrOutNORM(clrRED,"ERROR")
         << ": [gadget::InputWindowXWin::openTheWindow()] find visual failed"
         << std::endl << vprDEBUG_FLUSH;
      return 0;
   }

   mSWA.colormap = XCreateColormap(mXDisplay,
                                   RootWindow(mXDisplay, mVisual->screen),
                                   mVisual->visual, AllocNone);
   mSWA.background_pixel = BlackPixel(mXDisplay, mScreen);
   mSWA.border_pixel = WhitePixel(mXDisplay, mScreen);
   const unsigned int event_mask =
      ExposureMask | StructureNotifyMask | KeyPressMask | KeyReleaseMask |
      ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
      PointerMotionMask | StructureNotifyMask;
   mSWA.event_mask = event_mask;

   mXWindow = createWindow(DefaultRootWindow(mXDisplay), 1);
   createEmptyCursor(mXDisplay, mXWindow);

   setHints(mXWindow, const_cast<char*>(mInstName.c_str()),
            const_cast<char*>(mInstName.c_str()) , "VRJInputWindow", "VRJ Input Windows");

   XSelectInput(mXDisplay, mXWindow, event_mask);
   XMapWindow(mXDisplay, mXWindow);
   XFlush(mXDisplay);
   XRaiseWindow(mXDisplay, mXWindow);
   XClearWindow(mXDisplay, mXWindow);    // Try to clear the background

   vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
      << "[gadget::InputWindowXWin::openTheWindow()] done." << std::endl
      << vprDEBUG_FLUSH;

   XFree(vis_infos);

   return 1;
}
NativeWindowLinuxOpenGL::NativeWindowLinuxOpenGL(const int& width, const int& height, const char* title)
: NativeWindowLinux(width, height, title) {
	const int attrib[] = {
		GLX_RENDER_TYPE, GLX_RGBA_BIT,
		GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
		GLX_DOUBLEBUFFER, True,
		GLX_RED_SIZE, 1,
		GLX_GREEN_SIZE, 1,
		GLX_BLUE_SIZE, 1,
		GLX_SAMPLE_BUFFERS, 1,
		GLX_SAMPLES, 4,
		None
	};

	MainDisplay = XOpenDisplay(NULL);
	int screen = DefaultScreen(MainDisplay);
	Window root = RootWindow(MainDisplay, screen);

	int fbcount;
	PFNGLXCHOOSEFBCONFIGPROC glXChooseFBConfig = (PFNGLXCHOOSEFBCONFIGPROC)glXGetProcAddress((GLubyte*)"glXChooseFBConfig");
	GLXFBConfig* fbc = glXChooseFBConfig(MainDisplay, screen, attrib, &fbcount);

	PFNGLXGETVISUALFROMFBCONFIGPROC glXGetVisualFromFBConfig = (PFNGLXGETVISUALFROMFBCONFIGPROC)glXGetProcAddress((GLubyte*)"glXGetVisualFromFBConfig");
	XVisualInfo* visinfo = glXGetVisualFromFBConfig(MainDisplay, fbc[0]);

	XSetWindowAttributes attr;
	attr.background_pixel = 0;
	attr.border_pixel = 0;
	attr.colormap = XCreateColormap(MainDisplay, root, visinfo->visual, AllocNone);
	attr.backing_store = 0;
	attr.override_redirect = 0;
	attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask;

	MainWindow = XCreateWindow(
		MainDisplay,
		root,
		0, 0,
		width, height, 0,
		visinfo->depth,
		InputOutput,
		visinfo->visual,
		CWBackPixel | CWBorderPixel | CWColormap | CWBackingStore | CWOverrideRedirect | CWEventMask,
		&attr);

	XMapWindow(MainDisplay, MainWindow);
	XStoreName(MainDisplay, MainWindow, title);
	XRaiseWindow(MainDisplay, MainWindow);

	Atom WM_DELETE_WINDOW = XInternAtom(MainDisplay, "WM_DELETE_WINDOW", False);
	XSetWMProtocols(MainDisplay, MainWindow, &WM_DELETE_WINDOW, 1);

	if (true) {
		GLXContext tempContext = glXCreateContext(MainDisplay, visinfo, NULL, True);
		PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress((GLubyte*)"glXCreateContextAttribsARB");

		int fbcount = 0;
		GLXFBConfig* framebufferConfig = glXChooseFBConfig(MainDisplay, screen, 0, &fbcount);
		if (framebufferConfig) {
			const int attribs[] = {
				GLX_CONTEXT_MAJOR_VERSION_ARB, 4,
				GLX_CONTEXT_MINOR_VERSION_ARB, 5,
				GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
				0
			};
			glcontext = glXCreateContextAttribs(MainDisplay, framebufferConfig[0], NULL, True, attribs);
			glXMakeCurrent(MainDisplay, 0, 0);
			glXDestroyContext(MainDisplay, tempContext);
		}
	} else {
		glcontext = glXCreateContext(MainDisplay, visinfo, NULL, True);
	}
	XFree(visinfo);
}
Example #13
0
         short WPgrid_dialog(DBint grw_id)

/*      The grid dialogue.
 *
 *      In: grw_id = ID of WPGWIN that called us.
 *
 *      (C)2007-03-12 J.Kjellander
 *
 ******************************************************!*/

  {
   char     rubrik[81],close[81],help[81],edit[81],pos[81],
            res[81],show[81],hide[81],move[81],movett[81],
            edittt[81],showtt[81],hidett[81],bs1[81],bs2[81],
            closett[81],helptt[81];
   char    *typ[20];
   int      bh,wm_x1,wm_y1,wm_x2,wm_y2,butlen,bl1,bl2,actfunc_org;
   short    status,main_dx,main_dy,alt_x,alt_y,butlen1,butlen2,ly,lm;
   DBint    iwin_id,move_id,edit_id,show_id,hide_id,close_id,
            help_id,but_id;
   unsigned int dum1,dum2;
   DBVector newpos;
   WPWIN   *winptr;
   WPIWIN  *iwinpt;
   WPBUTT  *butptr;
   WPGWIN  *gwinpt;
   XEvent   event;
   XrmValue value;

/*
***Set actfunc during user action, see IG/include/futab.h.
*/
   actfunc_org = actfunc;
   actfunc = 103;
/*
***Is this the first time this function is called ?
***Initial window position.
*/
   if ( premiere )
     {
     iwin_x = iwin_y = 5;

     if ( XrmGetResource(xresDB,"varkon.grid.geometry",
                                "Varkon.Grid.Geometry",
                                 typ,&value) ) 
       XParseGeometry((char *)value.addr,&iwin_x,&iwin_y,&dum1,&dum2);

     premiere = FALSE;
     }
/*
***Get a C ptr to the graphical window that called us.
*/
   gwinpt = (WPGWIN *)wpwtab[grw_id].ptr;
/*
***During user interaction the dialogue window may get deleted
***and created again with new contents. This is where we start
***recreating a new instance.
*/
start:

/*
***Window title, position, resolution, move, edit, show, hide,
***close and help from the ini-file.
*/
   if ( !WPgrst("varkon.grid.title",rubrik) )           strcpy(rubrik,"Grid");
   if ( !WPgrst("varkon.grid.position.text",pos) )      strcpy(pos,"Position");
   if ( !WPgrst("varkon.grid.resolution.text",res) )    strcpy(res,"Resolution");
   if ( !WPgrst("varkon.grid.show.text",show) )         strcpy(show,"Show");
   if ( !WPgrst("varkon.grid.show.tooltip",showtt) )    strcpy(showtt,"");
   if ( !WPgrst("varkon.grid.hide.text",hide) )         strcpy(hide,"Hide");
   if ( !WPgrst("varkon.grid.hide.tooltip",hidett) )    strcpy(hidett,"");
   if ( !WPgrst("varkon.grid.move.text",move) )         strcpy(move,"Move");
   if ( !WPgrst("varkon.grid.move.tooltip",movett) )    strcpy(movett,"");
   if ( !WPgrst("varkon.grid.edit.text",edit) )         strcpy(edit,"Edit");
   if ( !WPgrst("varkon.grid.edit.tooltip",edittt) )    strcpy(edittt,"");
   if ( !WPgrst("varkon.input.close",close) )           strcpy(close,"Close");
   if ( !WPgrst("varkon.input.close.tooltip",closett) ) strcpy(closett,"");
   if ( !WPgrst("varkon.input.help",help) )             strcpy(help,"Help");
   if ( !WPgrst("varkon.input.help.tooltip",helptt) )   strcpy(helptt,"");
/*
***What is the 1.2*length of the longest text ?
***Don't include the title, it will fit anyhow.
*/
   butlen1 = 0;
   if ( WPstrl(pos)    > butlen1 ) butlen1 = WPstrl(pos);
   if ( WPstrl(res)    > butlen1 ) butlen1 = WPstrl(res);
   if ( WPstrl(move)   > butlen1 ) butlen1 = WPstrl(move);
   if ( WPstrl(edit)   > butlen1 ) butlen1 = WPstrl(edit);
   if ( WPstrl(show)   > butlen1 ) butlen1 = WPstrl(show);
   if ( WPstrl(hide)   > butlen1 ) butlen1 = WPstrl(hide);
   butlen1 *= 1.2;

   butlen2 = 0;
   if ( WPstrl(close)  > butlen2 ) butlen2 = WPstrl(close);
   if ( WPstrl(help)   > butlen2 ) butlen2 = WPstrl(help);
   butlen2 *= 1.8;
/*
***Calculate outside air (ly), button height (bh) and air between (lm).
*/
   ly = (short)(1.2*WPstrh());
   bh = (short)(1.8*WPstrh());
   lm = (short)(0.8*WPstrh());
/*
***Calculate the window size in X-direction.
*/
   main_dx = ly + butlen1 + ly + ly + butlen1 + ly;
/*
***Calculate the window size in Y-direction.
*/
   main_dy = ly + bh + lm + bh + 0 + bh + lm + bh + bh + bh + bh + bh + bh + ly;
/*
***Create the dialogue window as a WPIWIN.
*/
   WPwciw((short)iwin_x,(short)iwin_y,main_dx,main_dy,rubrik,&iwin_id);
/*
***Get a C-ptr to the WPIWIN.
*/
   winptr = WPwgwp((wpw_id)iwin_id);
   iwinpt = (WPIWIN *)winptr->ptr;
/*
***A vertical line.
*/
   alt_x  = ly + butlen1 + ly;
   alt_y  = ly + lm;
   WPcreate_3Dline(iwin_id,alt_x,alt_y,alt_x,alt_y + 4*bh + 2*ly - 2*lm);
/*
***Position and resolution texts.
*/
   alt_x  = ly;
   alt_y  = ly;
   WPcrlb((wpw_id)iwin_id,alt_x,alt_y,butlen1,bh,pos,&but_id);

   alt_x  = ly + butlen1 + ly + ly;
   WPcrlb((wpw_id)iwin_id,alt_x,alt_y,butlen1,bh,res,&but_id);
/*
***X, Y, DX and DY texts.
*/
   sprintf(bs1,"X = %g",gwinpt->grid_x);
   bl1 = WPstrl(bs1);
   sprintf(bs2,"Y = %g",gwinpt->grid_y);
   bl2 = WPstrl(bs2);
   if ( bl1 > bl2 ) butlen = bl1;
   else             butlen = bl2;

   alt_x  = (ly + butlen1 + ly - butlen)/2;
   alt_y  = ly + bh + lm;
   WPcrlb((wpw_id)iwin_id,alt_x,alt_y,bl1,bh,bs1,&but_id);

   alt_y  = ly + bh + lm + bh;
   WPcrlb((wpw_id)iwin_id,alt_x,alt_y,bl2,bh,bs2,&but_id);

   sprintf(bs1,"DX = %g",gwinpt->grid_dx);
   bl1 = WPstrl(bs1);
   sprintf(bs2,"DY = %g",gwinpt->grid_dy);
   bl2 = WPstrl(bs2);
   if ( bl1 > bl2 ) butlen = bl1;
   else             butlen = bl2;

   alt_x  = ly + ly + butlen1 + (ly + butlen1 + ly - butlen)/2;
   alt_y  = ly + bh + lm;
   WPcrlb((wpw_id)iwin_id,alt_x,alt_y,bl1,bh,bs1,&but_id);

   alt_y  = ly + bh + lm + bh;
   WPcrlb((wpw_id)iwin_id,alt_x,alt_y,bl2,bh,bs2,&but_id);
/*
***Move and edit.
*/
   alt_x  = ly;
   alt_y += bh + lm;
   status = WPcrpb((wpw_id)iwin_id,alt_x,alt_y,butlen1,bh,(short)2,
                           move,move,"",WP_BGND2,WP_FGND,&move_id);
   butptr = (WPBUTT *)iwinpt->wintab[move_id].ptr;
   strcpy(butptr->tt_str,movett);

   alt_x  = ly + butlen1 + ly + ly;
   status = WPcrpb((wpw_id)iwin_id,alt_x,alt_y,butlen1,bh,(short)2,
                           edit,edit,"",WP_BGND2,WP_FGND,&edit_id);
   butptr = (WPBUTT *)iwinpt->wintab[edit_id].ptr;
   strcpy(butptr->tt_str,edittt);
/*
***Show and hide.
*/
   alt_x  = ly;
   alt_y  += bh + bh;
   status = WPcrpb((wpw_id)iwin_id,alt_x,alt_y,butlen1,bh,(short)2,
                           show,show,"",WP_BGND2,WP_FGND,&show_id);
   butptr = (WPBUTT *)iwinpt->wintab[show_id].ptr;
   strcpy(butptr->tt_str,showtt);

   alt_x  = ly + butlen1 + ly + ly;
   status = WPcrpb((wpw_id)iwin_id,alt_x,alt_y,butlen1,bh,(short)2,
                           hide,hide,"",WP_BGND2,WP_FGND,&hide_id);
   butptr = (WPBUTT *)iwinpt->wintab[hide_id].ptr;
   strcpy(butptr->tt_str,hidett);
/*
***A horizontal line.
*/
   alt_x  = main_dx/8;
   alt_y  += bh + bh;
   WPcreate_3Dline(iwin_id,alt_x,alt_y,alt_x + 6*main_dx/8,alt_y);
/*
***Close and help.
*/
   alt_x  = ly;
   alt_y += bh;
   status = WPcrpb((wpw_id)iwin_id,alt_x,alt_y,butlen2,bh,(short)3,
                           close,close,"",WP_BGND2,WP_FGND,&close_id);
   butptr = (WPBUTT *)iwinpt->wintab[close_id].ptr;
   strcpy(butptr->tt_str,closett);

   alt_x  = main_dx - ly - butlen2;
   status = WPcrpb((wpw_id)iwin_id,alt_x,alt_y,butlen2,bh,(short)2,
                           help,help,"",WP_BGND2,WP_FGND,&help_id);
   butptr = (WPBUTT *)iwinpt->wintab[help_id].ptr;
   strcpy(butptr->tt_str,helptt);
/*
***Show the dialogue.
*/
   WPwshw(iwin_id);
   XRaiseWindow(xdisp,iwinpt->id.x_id);
/*
***Where did it actually get positioned ?
***This code copied from WPmsip().
*/
   XWindowEvent(xdisp,iwinpt->id.x_id,ExposureMask,&event);
   XPutBackEvent(xdisp,&event);
   WPgtwp(iwinpt->id.x_id,&wm_x1,&wm_y1);
/*
***Wait for action. SMBPOSM is not an issue in this situation.
*/
   status = 0;
loop:
   if ( WPwwtw(iwin_id,SLEVEL_V3_INP,&but_id) == SMBPOSM ) goto loop;
/*
***Move button.
*/
   if ( but_id == move_id )
     {
     WPaddmess_mcwin(IGgtts(44),WP_PROMPT);
     status = IGcpov(&newpos);
     WPerhg();    
     IGrsma();
     if ( status == 0 )
       {
       WPdelete_grid(grw_id);
       gwinpt->grid_x = newpos.x_gm;
       gwinpt->grid_y = newpos.y_gm;
       WPdraw_grid(grw_id);
       goto update;
       }
     else goto loop;
     }
/*
***Edit button.
*/
   else if ( but_id == edit_id )
     {
     status = get_resolution(gwinpt,&newpos.x_gm,&newpos.y_gm);
     if ( status == 0 )
       {
       WPdelete_grid(grw_id);
       gwinpt->grid_dx = newpos.x_gm;
       gwinpt->grid_dy = newpos.y_gm;
       WPdraw_grid(grw_id);
       goto update;
       }
     else goto loop;
     }
/*
***Show button.
*/
   else if ( but_id == show_id )
     {
     WPgrid_on(grw_id);
     WPdraw_grid(grw_id);
     goto loop;
     }
/*
**Hide button.
*/
   else if ( but_id == hide_id )
     {
     WPdelete_grid(grw_id);
     WPgrid_off(grw_id);
     goto loop;
     }
/*
***Close button.
*/
   else if ( but_id == close_id )
     {
     status = 0;
     goto exit;
     }
/*
***Help button.
*/
   else if ( but_id == help_id )
     {
     IGhelp();
     goto loop;
     }
/*
***Unknown event, should not happen.
*/
   else
     {
     WPbell();
     goto loop;
     }
/*
***A view was added or removed so we need to update the window.
***Before deleting it, update the variables for it's current position.
*/
update:
   WPgtwp(iwinpt->id.x_id,&wm_x2,&wm_y2);
   iwin_x = iwin_x + wm_x2 - wm_x1;
   iwin_y = iwin_y + wm_y2 - wm_y1;
   WPwdel(iwin_id);
   goto start;
/*
***Time to exit. Reset global actfunc. Remeber current position.
*/
exit:
   actfunc = actfunc_org;
   WPgtwp(iwinpt->id.x_id,&wm_x2,&wm_y2);
   iwin_x = iwin_x + wm_x2 - wm_x1;
   iwin_y = iwin_y + wm_y2 - wm_y1;
   WPwdel(iwin_id);

   return(status);
 }
Example #14
0
void WebBrowserObject::BrowserEvent(const char *etype, const char *data)
{
    if (!strcmp(etype, "key")) {
        int key = NoSymbol, state = 0;
        // Check for modifiers
        if (!strncmp(data, "ctrl:", 5)) {
            state = ControlMask;
            data += 5;
        } else
        if (!strncmp(data, "shift:", 6)) {
            state = ShiftMask;
            data += 6;
        } else
        if (!strncmp(data, "mod1:", 5)) {
            state = Mod1Mask;
            data += 5;
        }
        // Predefined key codes
        if (!strcmp(data, "home")) {
            key = XK_Home;
        } else
        if (!strcmp(data, "end")) {
            key = XK_End;
        } else
        if (!strcmp(data, "prevpage")) {
            key = XK_Page_Up;
        } else
        if (!strcmp(data, "nextpage")) {
            key = XK_Page_Down;
        } else
        if (!strcmp(data, "up")) {
            key = XK_Up;
        } else
        if (!strcmp(data, "down")) {
            key = XK_Down;
        } else
        if (!strcmp(data, "prev")) {
            key = XK_Left;
        } else
        if (!strcmp(data, "next")) {
            key = XK_Right;
        } else
        if (!strcmp(data, "accept")) {
            key = XK_Return;
        } else
        if (!strcmp(data, "nexttrack")) {
            key = XK_Tab;
        } else
        if (!strcmp(data, "prevtrack")) {
            key = XK_Tab;
            state = ShiftMask;
        } else {
            key = XStringToKeysym(data);
        }
        if (key && toplevel) {
            XKeyEvent event;
            event.display = GDK_WINDOW_XDISPLAY(toplevel->window);
            event.window = GDK_WINDOW_XID(toplevel->window);
            event.root = DefaultRootWindow(event.display);
            event.subwindow = None;
            event.time = CurrentTime;
            event.x = 1;
            event.y = 1;
            event.x_root = 1;
            event.y_root = 1;
            event.same_screen = TRUE;
            event.type = KeyPress;
            event.state = state;
            XLockDisplay(event.display);
            event.keycode = XKeysymToKeycode(event.display,key);
            XSendEvent(event.display, event.window, TRUE, KeyPressMask, (XEvent *)&event);
            XUnlockDisplay(event.display);
        }
    } else

    if (!strcmp(etype, "focus")) {
        if (!strcmp(data, "mozilla") && toplevel) {
            XLockDisplay(GDK_WINDOW_XDISPLAY(toplevel->window));
            XRaiseWindow(GDK_WINDOW_XDISPLAY(toplevel->window), GDK_WINDOW_XID(toplevel->window));
            XSync(GDK_WINDOW_XDISPLAY(toplevel->window), False);
            XUnlockDisplay(GDK_WINDOW_XDISPLAY(toplevel->window));
            gtk_widget_grab_focus(toplevel);
        } else
        if (!strcmp(data, "url") && toplevel) {
            gtk_widget_grab_focus(urlEntry);
        }
    } else

    if (!strcmp(etype, "toolbar")) {
        if (!strToBool(data)) {
            if (toolbar_flag && toplevel) {
                gtk_container_remove(GTK_CONTAINER(toolbarHBox), toolbar);
                gtk_container_remove(GTK_CONTAINER(toolbarHBox), urlEntry);
            }
            toolbar_flag = 0;
        } else {
            if (!toolbar_flag && toplevel) {
                gtk_box_pack_start(GTK_BOX(toolbarHBox), toolbar, FALSE, FALSE, 0);
                gtk_box_pack_start(GTK_BOX(toolbarHBox), urlEntry, TRUE, TRUE, 0);
            }
            toolbar_flag = 1;
        }
    }
}
Example #15
0
void KWM::raise(Window w){
  XRaiseWindow(qt_xdisplay(), w);
}
Example #16
0
void restack_desktop_cover ()
{
	if (_as_desktop_cover)
		XRaiseWindow (dpy, _as_desktop_cover);
}
Example #17
0
bool qapp::x11EventFilter(XEvent *event)  
{
	xwindow *client;
	Window w;
	XEvent ev;
	XConfigureRequestEvent *cev;
	XClientMessageEvent *mev;
	XCrossingEvent *xev;
	XCirculateRequestEvent *rev;
	XPropertyEvent *pev;
			
#ifdef DEBUGMSG		
#include "eventnames.h"
	if(event->type < 36)
		logmsg << "Received: " << event_names[event->type] << " (WId:" << event->xany.window << ")\n";
#endif
	while(waitpid(-1, NULL, WNOHANG) > 0);

	if(sighup)
	{
		wm_restart();
		tb_mn->readmenu();
		read_cprops();
		sighup = FALSE;
	}

	switch(event->type)
	{
		case DestroyNotify:
			w = event->xdestroywindow.window;

			if((client = cwindows.find(w)) != NULL)
			{
				clients.remove(client);
				
				if(smode && client->isstate())
					keyboard::tscreen();  // turn off screen mode

				tb_pg->draw_pager();
				
				return TRUE;
			}	
			if(tb_ap->remove(w))  // client on toolbar
				return TRUE;
				
			if(event->xdestroywindow.event != w)
				return TRUE;

			if(w == tb->winId() || w == tb_pg->winId() || w == tb_wl->winId() || w == tb_mn->winId() || w == tb_pb->winId())
				sig_term(SIGTERM);

			return FALSE;

		case MapNotify:
			if(event->xmap.event != event->xmap.window)
				return TRUE;
		
			if((client = pwindows.find(event->xmap.window)) != NULL)
				tb_pg->add(client);  // add to pager

			return FALSE;

		case UnmapNotify:
			if((client = cwindows.find(event->xunmap.window)) != NULL)
			{
				if(event->xunmap.send_event)
				{
					// client requested transitions 
					// normal -> withdrawn
					// iconic -> withdrawn
					
					client->withdraw();
				}
				else
					client->unmap();
				
				return TRUE;	
			}
			if(event->xunmap.event != event->xunmap.window)
				return TRUE;

			if(pwindows.find(event->xunmap.window) != NULL)
				tb_pg->draw_pager();
		
			return FALSE;

		case EnterNotify:
			xev = &event->xcrossing;
			
			if(event->xcrossing.window == qt_xrootwin())
			{
				stopautofocus();
				rootptr = TRUE;
			}
			else if(mrb == FALSE && menu_open == FALSE && (client = (xwindow *)widgetAt(xev->x_root, xev->y_root)) != NULL && 
			clients.find(client) != -1 && ((client = clients.current()) != focusclient || rootptr))
			{
				rootptr = FALSE;
				setinactive(client);  // old client to inactive, save new client
				
				if(xev->detail != NotifyInferior)
					client->startautofocus();

				client->setchildfocus(xev->time);
				client->setcmapfocus();
			}
			return FALSE;

		case ColormapNotify:
			if((client = cwindows.find(event->xcolormap.window)) != NULL)
			{
				client->setcmap(event->xcolormap.colormap);
				return TRUE;
			}	
			return FALSE;

		case PropertyNotify:
			pev = &event->xproperty;
			
			if((client = cwindows.find(pev->window)) != NULL)
			{
				if(pev->atom == XA_WM_NORMAL_HINTS)
				{
					client->get_wmnormalhints();
				}	
				else if(pev->atom == XA_WM_HINTS)
				{
					client->get_wmhints();
				}
				else if(pev->atom == XA_WM_NAME || pev->atom == XA_WM_ICON_NAME)
				{
					client->get_wmname();
				}
				else if(pev->atom == wm_colormaps)
				{
					client->get_colormaps();
					
					if(client == focusclient)
						client->setcmapfocus();
				}
				return TRUE;
			}
			return FALSE;

		case ConfigureNotify:
			if(event->xconfigure.event != event->xconfigure.window)
				return TRUE;
				
			if((client = pwindows.find(event->xconfigure.window)) != NULL)
			{
				tb_pg->draw_pager();
				while(XCheckTypedEvent(qt_xdisplay(), ConfigureNotify, &ev));
			}
			return TRUE;

		case ReparentNotify:
			if((client = cwindows.find(event->xreparent.window)) != NULL &&
			event->xreparent.parent != client->winId())
			{
				clients.remove(client);
				tb_pg->draw_pager();
			}	
			return TRUE;
		
		case ButtonPress:
			w = event->xbutton.window;
			
			if(w == qt_xrootwin())  // set focus to root window
				XSetInputFocus(qt_xdisplay(), w, RevertToPointerRoot, CurrentTime);

			if(w == tb->winId() || w == tb_pb->winId() || w == tb_ap->winId())
				XRaiseWindow(qt_xdisplay(), tb->winId());

			if(w == qt_xrootwin() || w == tb_pg->winId())
				install_colormap(None);
				
			return FALSE;

		case FocusOut:
			if(menu_open) // Qt 2.2.4 does not seem to like this if a menu is open
				return TRUE;

			return FALSE;

		case ClientMessage:
			mev = &event->xclient;
			
			if(mev->message_type == wm_change_state && mev->format == 32 && 
			mev->data.l[0] == IconicState && (client = cwindows.find(mev->window)) != NULL)
				client->iconify();

			return TRUE;	

		case CirculateRequest:
			rev = &event->xcirculaterequest;
			
			if(rev->place == PlaceOnTop)
				XRaiseWindow(qt_xdisplay(), rev->window);
			else
				XLowerWindow(qt_xdisplay(), rev->window);
				
			return TRUE;

		case ConfigureRequest:
			cev = &event->xconfigurerequest;
			XWindowChanges wc;
			
			if((client = cwindows.find(cev->window)) != NULL)
			{
#ifdef DEBUGMSG
	logmsg << "configure request to client (WId:" << client->winId() << ")\n";
#endif	
				if(cev->value_mask & (CWWidth|CWHeight|CWX|CWY))
				{
					if(smode && client->isstate())
						keyboard::tscreen(); 
					
					if(! client->is_tiled() || client == tmaxclient)
					{	
						int cx,cy,cw,ch;

						if(cev->value_mask & CWWidth)
						cw = cev->width;
						else	
							cw = client->width();

						if(cev->value_mask & CWHeight)
							ch = cev->height;
						else
							ch = client->getcheight();

						if((cev->value_mask & CWX) && ! client->is_tiled())
							cx = cev->x;
						else
							cx = client->x();

						if((cev->value_mask & CWY) && ! client->is_tiled())
					    		cy = cev->y;
						else
							cy = client->y();
						
						client->resize_request(cx, cy, cw, ch);
					}
					cev->value_mask &= ~(CWWidth|CWHeight|CWX|CWY);
				}
				
				if(! cev->value_mask)
					return TRUE;

				wc.width = client->width();
				wc.height = client->height();
				wc.x = client->x();
				wc.y = client->y();
				wc.border_width = 0;
				wc.sibling = cev->above;
				wc.stack_mode = cev->detail;

				XConfigureWindow(qt_xdisplay(), client->winId(), cev->value_mask, &wc);
				send_configurenotify(client);
			}
			else  // never mapped window
			{
				if(cev->window == tb->winId() || tb_ap->client_exists(cev->window))  // deny requests on toolbar
					return TRUE;

#ifdef DEBUGMSG
	logmsg << "configure request to unreparented window (WId:" << cev->window << ")\n";

#endif	

				wc.x = cev->x;
				wc.y = cev->y;
				wc.width = cev->width;
				wc.height = cev->height;
				cev->value_mask &= (CWX|CWY|CWWidth|CWHeight);
				
				XConfigureWindow(qt_xdisplay(), cev->window, cev->value_mask, &wc);	
			}
			return TRUE;
			
		case MapRequest:
			run_client(event->xmaprequest.window);
			return TRUE;
			
		case KeyPress:
			return(keyboard::keypress(&event->xkey));

		default:
			if(servershapes && event->type == (ShapeEventBase + ShapeNotify))
			{
				XShapeEvent *sev = (XShapeEvent *)event;
		
				if((client = cwindows.find(sev->window)) != NULL)
				{
					client->reshape();
					return TRUE;
				}	
			}
	}
	return FALSE;
}
Example #18
0
void X11Window::raise() const
{
    XRaiseWindow( XDISPLAY, m_wnd );
}
Example #19
0
// ----------------------------------------------------------------------------------------------
//    Switch to fullscreen.
// ----------------------------------------------------------------------------------------------
void wsFullScreen(wsTWindow *win)
{
    int decoration = 0;

    if (win->isFullScreen) {
        vo_x11_ewmh_fullscreen(_NET_WM_STATE_REMOVE); // removes fullscreen state if wm supports EWMH

        if (!(vo_fs_type & vo_wm_FULLSCREEN)) { // shouldn't be needed with EWMH fs
            win->X      = win->OldX;
            win->Y      = win->OldY;
            win->Width  = win->OldWidth;
            win->Height = win->OldHeight;
            decoration  = win->Decorations;
        }

#ifdef ENABLE_DPMS
        wsScreenSaverOn(wsDisplay);
#endif

        win->isFullScreen = False;
    } else {
        if (!(vo_fs_type & vo_wm_FULLSCREEN)) { // shouldn't be needed with EWMH fs
            win->OldX      = win->X;
            win->OldY      = win->Y;
            win->OldWidth  = win->Width;
            win->OldHeight = win->Height;
            vo_dx           = win->X;
            vo_dy           = win->Y;
            vo_dwidth       = win->Width;
            vo_dheight      = win->Height;
            vo_screenwidth  = wsMaxX;
            vo_screenheight = wsMaxY;
            xinerama_x      = wsOrgX;
            xinerama_y      = wsOrgY;
            update_xinerama_info();
            wsMaxX      = vo_screenwidth;
            wsMaxY      = vo_screenheight;
            wsOrgX      = xinerama_x;
            wsOrgY      = xinerama_y;
            win->X      = wsOrgX;
            win->Y      = wsOrgY;
            win->Width  = wsMaxX;
            win->Height = wsMaxY;
        }

        win->isFullScreen = True;
#ifdef ENABLE_DPMS
        wsScreenSaverOff(wsDisplay);
#endif

        vo_x11_ewmh_fullscreen(_NET_WM_STATE_ADD); // adds fullscreen state if wm supports EWMH
    }

    if (!(vo_fs_type & vo_wm_FULLSCREEN)) { // shouldn't be needed with EWMH fs
        vo_x11_decoration(wsDisplay, win->WindowID, decoration);
        vo_x11_sizehint(win->X, win->Y, win->Width, win->Height, 0);
        vo_x11_setlayer(wsDisplay, win->WindowID, win->isFullScreen);

        if ((!(win->isFullScreen)) & vo_ontop)
            vo_x11_setlayer(wsDisplay, win->WindowID, 1);

        XMoveResizeWindow(wsDisplay, win->WindowID, win->X, win->Y, win->Width, win->Height);
    }

    if (vo_wm_type == 0 && !(vo_fsmode & 16)) {
        XWithdrawWindow(wsDisplay, win->WindowID, wsScreen);
    }

    XMapRaised(wsDisplay, win->WindowID);
    XRaiseWindow(wsDisplay, win->WindowID);
    XFlush(wsDisplay);
}
Example #20
0
void RaiseMenuNParents(Menu *men)
{
  if(men->parent) RaiseMenuNParents(men->parent);
  XRaiseWindow(disp,men->win);
}
Example #21
0
void Track_station( /*@unused@*/ Widget w, /*@unused@*/ XtPointer clientData, /*@unused@*/ XtPointer callData) {
    static Widget pane, my_form, button_ok, button_close, button_clear, call, sep;
    Atom delw;

    if (!track_station_dialog) {

begin_critical_section(&track_station_dialog_lock, "track_gui.c:Track_station" );

        track_station_dialog = XtVaCreatePopupShell(langcode("WPUPTSP001"),
                xmDialogShellWidgetClass, appshell,
                XmNdeleteResponse, XmDESTROY,
                XmNdefaultPosition, FALSE,
                XmNfontList, fontlist1,
                NULL);

        pane = XtVaCreateWidget("Track_station pane",
                xmPanedWindowWidgetClass, 
                track_station_dialog,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                NULL);

        my_form =  XtVaCreateWidget("Track_station my_form",
                xmFormWidgetClass, 
                pane,
                XmNfractionBase, 3,
                XmNautoUnmanage, FALSE,
                XmNshadowThickness, 1,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                NULL);

        call = XtVaCreateManagedWidget(langcode("WPUPTSP002"),
                xmLabelWidgetClass, 
                my_form,
                XmNtopAttachment, XmATTACH_FORM,
                XmNtopOffset, 10,
                XmNbottomAttachment, XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_FORM,
                XmNleftOffset, 10,
                XmNrightAttachment, XmATTACH_NONE,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        track_station_data = XtVaCreateManagedWidget("Track_station track locate data", 
                xmTextFieldWidgetClass, 
                my_form,
                XmNeditable,   TRUE,
                XmNcursorPositionVisible, TRUE,
                XmNsensitive, TRUE,
                XmNshadowThickness,    1,
                XmNcolumns, 15,
                XmNwidth, ((15*7)+2),
                XmNmaxLength, 15,
                XmNbackground, colors[0x0f],
                XmNtopAttachment,XmATTACH_FORM,
                XmNtopOffset, 5,
                XmNbottomAttachment,XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_WIDGET,
                XmNleftWidget, call,
                XmNleftOffset, 10,
                XmNrightAttachment,XmATTACH_NONE,
                XmNnavigationType, XmTAB_GROUP,
                XmNtraversalOn, TRUE,
                XmNfontList, fontlist1,
                NULL);

        track_case_data  = XtVaCreateManagedWidget(langcode("WPUPTSP003"),
                xmToggleButtonWidgetClass,
                my_form,
                XmNtopAttachment, XmATTACH_WIDGET,
                XmNtopWidget, call,
                XmNtopOffset, 20,
                XmNbottomAttachment, XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_FORM,
                XmNleftOffset ,10,
                XmNrightAttachment, XmATTACH_NONE,
                XmNnavigationType, XmTAB_GROUP,
                XmNtraversalOn, TRUE,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        track_match_data  = XtVaCreateManagedWidget(langcode("WPUPTSP004"),
                xmToggleButtonWidgetClass,
                my_form,
                XmNtopAttachment, XmATTACH_WIDGET,
                XmNtopWidget, call,
                XmNtopOffset, 20,
                XmNbottomAttachment, XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_WIDGET,
                XmNleftWidget,track_case_data,
                XmNrightOffset ,20,
                XmNrightAttachment, XmATTACH_NONE,
                XmNnavigationType, XmTAB_GROUP,
                XmNtraversalOn, TRUE,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        sep = XtVaCreateManagedWidget("Track_station sep", 
                xmSeparatorGadgetClass,
                my_form,
                XmNorientation, XmHORIZONTAL,
                XmNtopAttachment,XmATTACH_WIDGET,
                XmNtopWidget,track_case_data,
                XmNtopOffset, 10,
                XmNbottomAttachment,XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_FORM,
                XmNrightAttachment,XmATTACH_FORM,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        button_ok = XtVaCreateManagedWidget(langcode("WPUPTSP005"),
                xmPushButtonGadgetClass, 
                my_form,
                XmNtopAttachment, XmATTACH_WIDGET,
                XmNtopWidget, sep,
                XmNtopOffset, 5,
                XmNbottomAttachment, XmATTACH_FORM,
                XmNbottomOffset, 5,
                XmNleftAttachment, XmATTACH_POSITION,
                XmNleftPosition, 0,
                XmNleftOffset, 5,
                XmNrightAttachment, XmATTACH_POSITION,
                XmNrightPosition, 1,
                XmNnavigationType, XmTAB_GROUP,
                XmNtraversalOn, TRUE,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        button_clear = XtVaCreateManagedWidget(langcode("WPUPTSP006"),
                xmPushButtonGadgetClass, 
                my_form,
                XmNtopAttachment, XmATTACH_WIDGET,
                XmNtopWidget, sep,
                XmNtopOffset, 5,
                XmNbottomAttachment, XmATTACH_FORM,
                XmNbottomOffset, 5,
                XmNleftAttachment, XmATTACH_POSITION,
                XmNleftPosition, 1,
                XmNrightAttachment, XmATTACH_POSITION,
                XmNrightPosition, 2,
                XmNnavigationType, XmTAB_GROUP,
                XmNtraversalOn, TRUE,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        button_close = XtVaCreateManagedWidget(langcode("UNIOP00003"),
                xmPushButtonGadgetClass, 
                my_form,
                XmNtopAttachment, XmATTACH_WIDGET,
                XmNtopWidget, sep,
                XmNtopOffset, 5,
                XmNbottomAttachment, XmATTACH_FORM,
                XmNbottomOffset, 5,
                XmNleftAttachment, XmATTACH_POSITION,
                XmNleftPosition, 2,
                XmNrightAttachment, XmATTACH_POSITION,
                XmNrightPosition, 3,
                XmNrightOffset, 5,
                XmNnavigationType, XmTAB_GROUP,
                XmNtraversalOn, TRUE,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        XtAddCallback(button_ok, XmNactivateCallback, Track_station_now, track_station_dialog);
        XtAddCallback(button_close, XmNactivateCallback, track_station_destroy_shell, track_station_dialog);
        XtAddCallback(button_clear, XmNactivateCallback, Track_station_clear, track_station_dialog);

        XmToggleButtonSetState(track_case_data,FALSE,FALSE);
        XmToggleButtonSetState(track_match_data,TRUE,FALSE);

        pos_dialog(track_station_dialog);

        delw = XmInternAtom(XtDisplay(track_station_dialog),"WM_DELETE_WINDOW", FALSE);
        XmAddWMProtocolCallback(track_station_dialog, delw, track_station_destroy_shell, (XtPointer)track_station_dialog);

//        if (track_station_on==1)
            XmTextFieldSetString(track_station_data,tracking_station_call);

        XtManageChild(my_form);
        XtManageChild(pane);

end_critical_section(&track_station_dialog_lock, "track_gui.c:Track_station" );

        XtPopup(track_station_dialog,XtGrabNone);
        fix_dialog_size(track_station_dialog);

        // Move focus to the Cancel button.  This appears to highlight the
        // button fine, but we're not able to hit the <Enter> key to
        // have that default function happen.  Note:  We _can_ hit the
        // <SPACE> key, and that activates the option.
//        XmUpdateDisplay(track_station_dialog);
        XmProcessTraversal(button_close, XmTRAVERSE_CURRENT);

    } else
        (void)XRaiseWindow(XtDisplay(track_station_dialog), XtWindow(track_station_dialog));
}
Example #22
0
File: mdmwm.c Project: AlbertJP/mdm
static void
event_process (XEvent *ev)
{
	MdmWindow *gw;
	Window w;
	XWindowChanges wchanges;

	trap_push ();

	switch (ev->type) {
	case MapRequest:
		w = ev->xmaprequest.window;
		gw = find_window (w, FALSE);
		if (gw == NULL) {
			if (ev->xmaprequest.parent == wm_root) {
				XGrabServer (wm_disp);
				gw = add_window (w,
						 TRUE /* center */,
						 FALSE /* is_mapped */);
				XUngrabServer (wm_disp);
			}
		}
		XMapWindow (wm_disp, w);
		break;
	case ConfigureRequest:
		XGrabServer (wm_disp);
		w = ev->xconfigurerequest.window;
		gw = find_window (w, FALSE);
		wchanges.border_width = ev->xconfigurerequest.border_width;
		wchanges.sibling = ev->xconfigurerequest.above;
		wchanges.stack_mode = ev->xconfigurerequest.detail;
		if (gw == NULL ||
		    gw->deco == None) {
			wchanges.x = ev->xconfigurerequest.x;
			wchanges.y = ev->xconfigurerequest.y;
		} else {
			wchanges.x = 1;
			wchanges.y = 1;
		}
		wchanges.width = ev->xconfigurerequest.width;
		wchanges.height = ev->xconfigurerequest.height;
		XConfigureWindow (wm_disp,
				  w,
				  ev->xconfigurerequest.value_mask,
				  &wchanges);
		if (gw != NULL) {
			gw->x = ev->xconfigurerequest.x;
			gw->y = ev->xconfigurerequest.y;
			if (gw->deco != None) {
				wchanges.x = ev->xconfigurerequest.x - 1;
				wchanges.y = ev->xconfigurerequest.y - 1;
				wchanges.width = ev->xconfigurerequest.width + 2
					+ 2*ev->xconfigurerequest.border_width;;
				wchanges.height = ev->xconfigurerequest.height + 2
					+ 2*ev->xconfigurerequest.border_width;;
				wchanges.border_width = 0;
				XConfigureWindow (wm_disp,
						  gw->deco,
						  ev->xconfigurerequest.value_mask,
						  &wchanges);
				center_x_window (gw, gw->deco, gw->win);
			} else {
				center_x_window (gw, gw->win, gw->win);
			}
			shadow_follow (gw);
		}
		XUngrabServer (wm_disp);
		break;
	case CirculateRequest:
		w = ev->xcirculaterequest.window;
		gw = find_window (w, FALSE);
		if (gw == NULL) {
			if (ev->xcirculaterequest.place == PlaceOnTop)
				XRaiseWindow (wm_disp, w);
			else
				XLowerWindow (wm_disp, w);
		} else {
			if (ev->xcirculaterequest.place == PlaceOnTop) {
				if (gw->shadow != None)
					XRaiseWindow (wm_disp, gw->shadow);
				if (gw->deco != None)
					XRaiseWindow (wm_disp, gw->deco);
				else
					XRaiseWindow (wm_disp, gw->win);
			} else {
				if (gw->deco != None)
					XLowerWindow (wm_disp, gw->deco);
				else
					XLowerWindow (wm_disp, gw->win);
				if (gw->shadow != None)
					XLowerWindow (wm_disp, gw->shadow);
			}
		}
		break;
	case MapNotify:
		w = ev->xmap.window;
		gw = find_window (w, FALSE);
		if (gw != NULL) {
			if (gw->ignore_next_map > 0) {
				gw->ignore_next_map --;
				break;
			}
			if ( ! ev->xmap.override_redirect &&
			     focus_new_windows) {
				mdm_wm_focus_window (w);
			}
		}
		break;
	case UnmapNotify:
		w = ev->xunmap.window;
		gw = find_window (w, FALSE);
		if (gw != NULL) {
			if (gw->ignore_next_unmap > 0) {
				gw->ignore_next_unmap --;
				break;
			}
			XGrabServer (wm_disp);
			if (gw->deco != None)
				XUnmapWindow (wm_disp, gw->deco);
			if (gw->shadow != None)
				XUnmapWindow (wm_disp, gw->shadow);
			reparent_to_root (gw);
			remove_window (w);
			XDeleteProperty (wm_disp, w, XA_WM_STATE);
			if (w != wm_login_window)
				revert_focus_to_login ();
			XUngrabServer (wm_disp);
		}
		break;
	case DestroyNotify:
		w = ev->xdestroywindow.window;
		gw = find_window (w, FALSE);
		if (gw != NULL) {
			XGrabServer (wm_disp);
			remove_window (w);
			if (w != wm_login_window)
				revert_focus_to_login ();
			XUngrabServer (wm_disp);
		}
		break;
	case EnterNotify:
		w = ev->xcrossing.window;
		gw = find_window (w, TRUE);
		if (gw != NULL)
			mdm_wm_focus_window (gw->win);
		break;
	case PropertyNotify:
		if (ev->xproperty.atom == XA_NET_WM_STRUT)
		{
			mdm_wm_update_struts (ev->xproperty.display, 
					      ev->xproperty.window);
			constrain_all_windows ();
		}
		break;
	default:
		break;
	}

	trap_pop ();
}
Example #23
0
void OS_X11::move_window_to_foreground() {

	XRaiseWindow(x11_display,x11_window);
}
Example #24
0
//This function is copied from xosc and is under the LGPL
static void
stay_on_top(Display * dpy, Window win)
{
  Atom gnome, net_wm, type;
  int format;
  unsigned long nitems, bytesafter;
  unsigned char *args = NULL;
  Window root = DefaultRootWindow(dpy);

  gnome = XInternAtom(dpy, "_WIN_SUPPORTING_WM_CHECK", False);
  net_wm = XInternAtom(dpy, "_NET_SUPPORTED", False);

  /*
   * gnome-compilant 
   * tested with icewm + WindowMaker 
   */
  if (Success == XGetWindowProperty
      (dpy, root, gnome, 0, (65536 / sizeof(long)), False,
       AnyPropertyType, &type, &format, &nitems, &bytesafter, &args) &&
      nitems > 0) {
    /*
     * FIXME: check capabilities 
     */
    XClientMessageEvent xev;
    Atom gnome_layer = XInternAtom(dpy, "_WIN_LAYER", False);

    memset(&xev, 0, sizeof(xev));
    xev.type = ClientMessage;
    xev.window = win;
    xev.message_type = gnome_layer;
    xev.format = 32;
    xev.data.l[0] = 6 /* WIN_LAYER_ONTOP */ ;

    XSendEvent(dpy, DefaultRootWindow(dpy), False, SubstructureNotifyMask,
               (XEvent *) & xev);
    XFree(args);
  }
  /*
   * netwm compliant.
   * tested with kde 
   */
  else if (Success == XGetWindowProperty
           (dpy, root, net_wm, 0, (65536 / sizeof(long)), False,
            AnyPropertyType, &type, &format, &nitems, &bytesafter, &args)
           && nitems > 0) {
    XEvent e;
    Atom net_wm_state = XInternAtom(dpy, "_NET_WM_STATE", False);
    Atom net_wm_top = XInternAtom(dpy, "_NET_WM_STATE_STAYS_ON_TOP", False);

    memset(&e, 0, sizeof(e));
    e.xclient.type = ClientMessage;
    e.xclient.message_type = net_wm_state;
    e.xclient.display = dpy;
    e.xclient.window = win;
    e.xclient.format = 32;
    e.xclient.data.l[0] = 1 /* _NET_WM_STATE_ADD */ ;
    e.xclient.data.l[1] = net_wm_top;
    e.xclient.data.l[2] = 0l;
    e.xclient.data.l[3] = 0l;
    e.xclient.data.l[4] = 0l;

    XSendEvent(dpy, DefaultRootWindow(dpy), False,
               SubstructureRedirectMask, &e);
    XFree(args);
  }
  XRaiseWindow(dpy, win);
}
Example #25
0
/*
 * Raise a term
 */
static void term_raise(term_data *td)
{
	Widget widget = (Widget)(td->widget);

	XRaiseWindow(XtDisplay(XtParent(widget)), XtWindow(XtParent(widget)));
}
Example #26
0
int main(int argc, char **argv) {

    struct aXInfo xinfo;
    struct aOpts opts = {
        alock_authmodules[0],
        alock_inputs[0],
        alock_cursors[0],
        alock_backgrounds[0],
    };

#if HAVE_X11_EXTENSIONS_XF86MISC_H
    int xf86misc_major = -1;
    int xf86misc_minor = -1;
#endif

    int arg;
    const char *optarg;
    const char *auth_args = NULL;
    const char *input_args = NULL;
    const char *cursor_args = NULL;
    const char *background_args = NULL;

    /* parse options */
    if (argc > 1) {
        for (arg = 1; arg < argc; arg++) {
            if (!strcmp(argv[arg], "-bg")) {
                optarg = argv[++arg];
                if (optarg != NULL) {

                    struct aBackground **i;
                    if (strcmp(optarg, "list") == 0) {
                        printf("list of available background modules:\n");
                        for (i = alock_backgrounds; *i; ++i) {
                            printf("%s\n", (*i)->name);
                        }
                        exit(EXIT_SUCCESS);
                    }

                    for (i = alock_backgrounds; *i; ++i) {
                        if (strstr(optarg, (*i)->name) == optarg) {
                            background_args = optarg;
                            opts.background = *i;
                            break;
                        }
                    }

                    if (*i == NULL) {
                        fprintf(stderr, "alock: background module not found\n");
                        exit(EXIT_FAILURE);
                    }

                }
                else {
                    fprintf(stderr, "alock: option requires an argument -- '%s'\n", "bg");
                    exit(EXIT_FAILURE);
                }
            }
            else if (!strcmp(argv[arg], "-auth")) {
                optarg = argv[++arg];
                if (optarg != NULL) {

                    struct aAuth **i;
                    if (strcmp(optarg, "list") == 0) {
                        printf("list of available authentication modules:\n");
                        for (i = alock_authmodules; *i; ++i) {
                            printf("%s\n", (*i)->name);
                        }
                        exit(EXIT_SUCCESS);
                    }

                    for (i = alock_authmodules; *i; ++i) {
                        if (strstr(optarg, (*i)->name) == optarg) {
                            auth_args = optarg;
                            opts.auth = *i;
                            break;
                        }
                    }

                    if (*i == NULL) {
                        fprintf(stderr, "alock: authentication module not found\n");
                        exit(EXIT_FAILURE);
                    }

                }
                else {
                    fprintf(stderr, "alock: option requires an argument -- '%s'\n", "auth");
                    exit(EXIT_FAILURE);
                }
            }
            else if (!strcmp(argv[arg], "-cursor")) {
                optarg = argv[++arg];
                if (optarg != NULL) {

                    struct aCursor **i;
                    if (strcmp(argv[arg], "list") == 0) {
                        printf("list of available cursor modules:\n");
                        for (i = alock_cursors; *i; ++i) {
                            printf("%s\n", (*i)->name);
                        }
                        exit(EXIT_SUCCESS);
                    }

                    for (i = alock_cursors; *i; ++i) {
                        if (strstr(optarg, (*i)->name) == optarg) {
                            cursor_args = optarg;
                            opts.cursor = *i;
                            break;
                        }
                    }

                    if (*i == NULL) {
                        fprintf(stderr, "alock: cursor module not found\n");
                        exit(EXIT_FAILURE);
                    }

                }
                else {
                    fprintf(stderr, "alock: option requires an argument -- '%s'\n", "cursor");
                    exit(EXIT_FAILURE);
                }
            }
            else if (!strcmp(argv[arg], "-input")) {
                optarg = argv[++arg];
                if (optarg != NULL) {

                    struct aInput **i;
                    if (strcmp(argv[arg], "list") == 0) {
                        printf("list of available input modules:\n");
                        for (i = alock_inputs; *i; ++i) {
                            printf("%s\n", (*i)->name);
                        }
                        exit(EXIT_SUCCESS);
                    }

                    for (i = alock_inputs; *i; ++i) {
                        if (strstr(optarg, (*i)->name) == optarg) {
                            input_args = optarg;
                            opts.input = *i;
                            break;
                        }
                    }

                    if (*i == NULL) {
                        fprintf(stderr, "alock: input module not found\n");
                        exit(EXIT_FAILURE);
                    }

                }
                else {
                    fprintf(stderr, "alock: option requires an argument -- '%s'\n", "input");
                    exit(EXIT_FAILURE);
                }
            }
            else if (strcmp(argv[arg], "-h") == 0) {
                printf("alock [-h] [-auth type:options] [-bg type:options]"
                       " [-cursor type:options] [-input type:options]\n");
                exit(EXIT_SUCCESS);
            }
            else {
                fprintf(stderr, "alock: invalid option '%s'\n", argv[arg]);
                exit(EXIT_FAILURE);
            }
        }
    }

    /* required for correct input handling */
    setlocale(LC_ALL, "");

    initXInfo(&xinfo);
    if (detectOtherInstance(&xinfo)) {
        fprintf(stderr, "alock: another instance seems to be running\n");
        exit(EXIT_FAILURE);
    }

    if (opts.auth->init(auth_args) == 0) {
        fprintf(stderr, "alock: failed init of [%s] with [%s]\n",
                opts.auth->name, auth_args);
        exit(EXIT_FAILURE);
    }

    /* We can be installed setuid root to support shadow passwords,
       and we don't need root privileges any longer.  --marekm */
    setuid(getuid());

    if (opts.input->init(input_args, &xinfo) == 0) {
        fprintf(stderr, "alock: failed init of [%s] with [%s]\n",
                opts.input->name, input_args);
        exit(EXIT_FAILURE);
    }
    if (opts.background->init(background_args, &xinfo) == 0) {
        fprintf(stderr, "alock: failed init of [%s] with [%s]\n",
                opts.background->name, background_args);
        exit(EXIT_FAILURE);
    }
    if (opts.cursor->init(cursor_args, &xinfo) == 0) {
        fprintf(stderr, "alock: failed init of [%s] with [%s]\n",
                opts.cursor->name, cursor_args);
        exit(EXIT_FAILURE);
    }

    {
        int scr;
        for (scr = 0; scr < xinfo.screens; scr++) {

            XSelectInput(xinfo.display, xinfo.window[scr], KeyPressMask|KeyReleaseMask);
            XMapWindow(xinfo.display, xinfo.window[scr]);
            XRaiseWindow(xinfo.display, xinfo.window[scr]);

        }
    }

    /* try to grab 2 times, another process (windowmanager) may have grabbed
     * the keyboard already */
    if ((XGrabKeyboard(xinfo.display, xinfo.window[0], True, GrabModeAsync, GrabModeAsync,
                          CurrentTime)) != GrabSuccess) {
        sleep(1);
        if ((XGrabKeyboard(xinfo.display, xinfo.window[0], True, GrabModeAsync, GrabModeAsync,
                        CurrentTime)) != GrabSuccess) {
            printf("alock: couldnt grab the keyboard\n");
            exit(EXIT_FAILURE);
        }
    }

#if HAVE_X11_EXTENSIONS_XF86MISC_H
    {
        if (XF86MiscQueryVersion(xinfo.display, &xf86misc_major, &xf86misc_minor) == True) {

            if (xf86misc_major >= 0 &&
                xf86misc_minor >= 5 &&
                XF86MiscSetGrabKeysState(xinfo.display, False) == MiscExtGrabStateLocked) {

                fprintf(stderr, "alock: cant disable xserver hotkeys to remove grabs\n");
                exit(EXIT_FAILURE);
            }

            printf("disabled AllowDeactivateGrabs and AllowClosedownGrabs\n");
        }
    }
#endif

    /* TODO: think about it: do we really need NR_SCREEN cursors ? we grab the
     * pointer on :*.0 anyway ... */
    if (XGrabPointer(xinfo.display, xinfo.window[0], False, None,
                     GrabModeAsync, GrabModeAsync, None, xinfo.cursor[0], CurrentTime) != GrabSuccess) {
        XUngrabKeyboard(xinfo.display, CurrentTime);
        fprintf(stderr, "alock: couldnt grab the pointer\n");
        exit(EXIT_FAILURE);
    }

    registerInstance(&xinfo);
    eventLoop(&opts, &xinfo);
    unregisterInstance(&xinfo);

    opts.auth->deinit();
    opts.input->deinit(&xinfo);
    opts.cursor->deinit(&xinfo);
    opts.background->deinit(&xinfo);

#if HAVE_X11_EXTENSIONS_XF86MISC_H
    if (xf86misc_major >= 0 && xf86misc_minor >= 5) {
        XF86MiscSetGrabKeysState(xinfo.display, True);
        XFlush(xinfo.display);
    }
#endif

    XCloseDisplay(xinfo.display);

    return EXIT_SUCCESS;
}
Example #27
0
// Enter fullscreen mode
//
static void enterFullscreenMode(_GLFWwindow* window)
{
    if (!_glfw.x11.saver.changed)
    {
        // Remember old screen saver settings
        XGetScreenSaver(_glfw.x11.display,
                        &_glfw.x11.saver.timeout,
                        &_glfw.x11.saver.interval,
                        &_glfw.x11.saver.blanking,
                        &_glfw.x11.saver.exposure);

        // Disable screen saver
        XSetScreenSaver(_glfw.x11.display, 0, 0, DontPreferBlanking,
                        DefaultExposures);

        _glfw.x11.saver.changed = GL_TRUE;
    }

    _glfwSetVideoMode(window->monitor, &window->videoMode);

    if (_glfw.x11.hasEWMH &&
        _glfw.x11.NET_WM_STATE != None &&
        _glfw.x11.NET_WM_STATE_FULLSCREEN != None)
    {
        if (_glfw.x11.NET_ACTIVE_WINDOW != None)
        {
            // Ask the window manager to raise and focus the GLFW window
            // Only focused windows with the _NET_WM_STATE_FULLSCREEN state end
            // up on top of all other windows ("Stacking order" in EWMH spec)

            XEvent event;
            memset(&event, 0, sizeof(event));

            event.type = ClientMessage;
            event.xclient.window = window->x11.handle;
            event.xclient.format = 32; // Data is 32-bit longs
            event.xclient.message_type = _glfw.x11.NET_ACTIVE_WINDOW;
            event.xclient.data.l[0] = 1; // Sender is a normal application
            event.xclient.data.l[1] = 0; // We don't really know the timestamp

            XSendEvent(_glfw.x11.display,
                       _glfw.x11.root,
                       False,
                       SubstructureNotifyMask | SubstructureRedirectMask,
                       &event);
        }

        // Ask the window manager to make the GLFW window a fullscreen window
        // Fullscreen windows are undecorated and, when focused, are kept
        // on top of all other windows

        XEvent event;
        memset(&event, 0, sizeof(event));

        event.type = ClientMessage;
        event.xclient.window = window->x11.handle;
        event.xclient.format = 32; // Data is 32-bit longs
        event.xclient.message_type = _glfw.x11.NET_WM_STATE;
        event.xclient.data.l[0] = _NET_WM_STATE_ADD;
        event.xclient.data.l[1] = _glfw.x11.NET_WM_STATE_FULLSCREEN;
        event.xclient.data.l[2] = 0; // No secondary property
        event.xclient.data.l[3] = 1; // Sender is a normal application

        XSendEvent(_glfw.x11.display,
                   _glfw.x11.root,
                   False,
                   SubstructureNotifyMask | SubstructureRedirectMask,
                   &event);
    }
    else if (window->x11.overrideRedirect)
    {
        // In override-redirect mode we have divorced ourselves from the
        // window manager, so we need to do everything manually

        GLFWvidmode mode;
        _glfwPlatformGetVideoMode(window->monitor, &mode);

        XRaiseWindow(_glfw.x11.display, window->x11.handle);
        XSetInputFocus(_glfw.x11.display, window->x11.handle,
                       RevertToParent, CurrentTime);
        XMoveWindow(_glfw.x11.display, window->x11.handle, 0, 0);
        XResizeWindow(_glfw.x11.display, window->x11.handle,
                      mode.width, mode.height);
    }
}
Example #28
0
int
main(int argc, char *argv[])
{
	KeySym key;
	XEvent event;
	int hidden = 1;
	int fullscreen = 0;
	int i, tmp;
	int old_height = 0;
	Window tmpwin, last_focused, current_focused;
	XWindowAttributes wa;

	/* strip the path from argv[0] if there is one */
	progname = strrchr(argv[0], '/');
	if (!progname)
		progname = argv[0];
	else
		progname++;

	for (i = 1; i < argc; i++) {
		if (!strcmp(argv[i], "-h")) {
			printf("%s:\n"
				   "-e: program to execute\n"
				   "you can configure me via xresources:\n"
				   "%s*foo:value\n"
				   "foo can be any standard xterm/urxvt/st xresource or:\n"
				   "resource               default value\n\n"
				   "term:                  xterm\n"
				   "restart:               0\n"
				   "xOffset:               0\n"
				   "yOffset:               0\n"
				   "xrandrSupport:         0\n"
				   "screenWidth:           Display width\n"
				   "consoleHeight:         10\n"
				   "aniDelay:              40\n"
				   "stepSize;              1\n"
				   "toggleKey:             ControlAlt+y\n"
				   "keySmaller:            Control+KP_Subtract\n"
				   "keyBigger:             Control+KP_Add\n" "keyFull:               Alt+F11\n", progname, progname);
			exit(0);
		}
	}

	if (!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, " can not open dpy %s", XDisplayName(NULL));
	}
	screen = DefaultScreen(dpy);
	root = RootWindow(dpy, screen);
	XSetErrorHandler(handle_xerror);
	cursor = XCreateFontCursor(dpy, XC_double_arrow);
	get_defaults();
	init_win();
	init_command(argc, argv);
	init_xterm(1);
	while (1) {
		XNextEvent(dpy, &event);
		switch (event.type) {
		case FocusOut:
			/* Always keep input focus when visible */
			if (!hidden)
				XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime);
			break;
		case EnterNotify:
			XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime);
			XSync(dpy, False);
			break;
		case LeaveNotify:
			if (last_focused && event.xcrossing.detail != NotifyInferior) {
				XSetInputFocus(dpy, last_focused, RevertToPointerRoot, CurrentTime);
				XSync(dpy, False);
			}
			break;
		case KeyPress:
			key = XKeycodeToKeysym(dpy, event.xkey.keycode, 0);
			if (key == opt_key) {
				if (!hidden) {
					XGetInputFocus(dpy, &current_focused, &revert_to);
					if (last_focused && current_focused == termwin)
						XSetInputFocus(dpy, last_focused, RevertToPointerRoot, CurrentTime);
					/* else
					   XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); */
					if (opt_step && !fullscreen)
						roll(UP);
					XUnmapWindow(dpy, win);
					hidden = 1;
					XSync(dpy, False);
				}
				else {
					XGetInputFocus(dpy, &last_focused, &revert_to);
					last_focused = get_toplevel_parent(last_focused);

					if (opt_step && !fullscreen) {
						XGrabServer(dpy);
						roll(DOWN);
						XUngrabServer(dpy);
					}
					else if (opt_xrandr)
						update_geom(last_focused);
					XMoveWindow(dpy, win, opt_x, opt_y);
					XMapWindow(dpy, win);
					XRaiseWindow(dpy, win);
					XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime);
					hidden = 0;
					XSync(dpy, False);
					XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime);
					XSync(dpy, False);
				}
				break;
			}
			if (!hidden) {
				if (key == opt_key_full) {
					if (!fullscreen) {
						old_height = height;
						height = get_optimal_height(get_display_height());
						fullscreen = 1;
					}
					else {
						height = old_height;
						fullscreen = 0;
					}
				}

				/* update height inc just in case something changed for the
				 * terminal, i.e. font size */
				resize_inc = get_height_inc();
				if (key == opt_key_bigger)
					height += resize_inc;
				if (key == opt_key_smaller)
					height -= resize_inc;
				if (height < resize_inc)
					height = resize_inc;
				height = get_optimal_height(height);
				resize_term(opt_width, height);
				XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime);
				XSync(dpy, False);
			}
			break;
		case ButtonPress:
			resize();
			XSync(dpy, False);
			break;
		case UnmapNotify:
			if (event.xunmap.window == termwin) {
				if (opt_restart) {
					if (opt_restart_hidden) {
						roll(UP);
						hidden = 1;
					}
					init_xterm(0);
					XSync(dpy, False);
					if (opt_restart_hidden && last_focused)
						XSetInputFocus(dpy, last_focused, RevertToPointerRoot, CurrentTime);
					else
						XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime);
				}
				else {
					if (last_focused)
						XSetInputFocus(dpy, last_focused, RevertToPointerRoot, CurrentTime);
					XSync(dpy, False);
					exit(0);
				}
			}
			break;
		}
	}
	return 0;
}
Example #29
0
static void enterFullscreenMode(_GLFWwindow* window)
{

    XEvent event;
    if (!_glfwLibrary.X11.saver.changed)
    {
	// Remember old screen saver settings
	XGetScreenSaver(_glfwLibrary.X11.display,
			&_glfwLibrary.X11.saver.timeout,
			&_glfwLibrary.X11.saver.interval,
			&_glfwLibrary.X11.saver.blanking,
			&_glfwLibrary.X11.saver.exposure);

	// Disable screen saver
	XSetScreenSaver(_glfwLibrary.X11.display, 0, 0, DontPreferBlanking,
			DefaultExposures);

	_glfwLibrary.X11.saver.changed = GL_TRUE;
    }

    _glfwSetVideoMode(&window->width, &window->height,
		      &window->refreshRate);

    if (_glfwLibrary.X11.hasEWMH &&
	_glfwLibrary.X11.wmState != None &&
	_glfwLibrary.X11.wmStateFullscreen != None)
    {
	if (_glfwLibrary.X11.wmActiveWindow != None)
	{
	    // Ask the window manager to raise and focus the GLFW window
	    // Only focused windows with the _NET_WM_STATE_FULLSCREEN state end
	    // up on top of all other windows ("Stacking order" in EWMH spec)

	    XEvent event;
	    memset(&event, 0, sizeof(event));

	    event.type = ClientMessage;
	    event.xclient.window = window->X11.handle;
	    event.xclient.format = 32; // Data is 32-bit longs
	    event.xclient.message_type = _glfwLibrary.X11.wmActiveWindow;
	    event.xclient.data.l[0] = 1; // Sender is a normal application
	    event.xclient.data.l[1] = 0; // We don't really know the timestamp

	    XSendEvent(_glfwLibrary.X11.display,
		       _glfwLibrary.X11.root,
		       False,
		       SubstructureNotifyMask | SubstructureRedirectMask,
		       &event);
	}

	// Ask the window manager to make the GLFW window a fullscreen window
	// Fullscreen windows are undecorated and, when focused, are kept
	// on top of all other windows

	memset(&event, 0, sizeof(event));

	event.type = ClientMessage;
	event.xclient.window = window->X11.handle;
	event.xclient.format = 32; // Data is 32-bit longs
	event.xclient.message_type = _glfwLibrary.X11.wmState;
	event.xclient.data.l[0] = _NET_WM_STATE_ADD;
	event.xclient.data.l[1] = _glfwLibrary.X11.wmStateFullscreen;
	event.xclient.data.l[2] = 0; // No secondary property
	event.xclient.data.l[3] = 1; // Sender is a normal application

	XSendEvent(_glfwLibrary.X11.display,
		   _glfwLibrary.X11.root,
		   False,
		   SubstructureNotifyMask | SubstructureRedirectMask,
		   &event);
    }
    else if (window->X11.overrideRedirect)
    {
	// In override-redirect mode we have divorced ourselves from the
	// window manager, so we need to do everything manually

	XRaiseWindow(_glfwLibrary.X11.display, window->X11.handle);
	XSetInputFocus(_glfwLibrary.X11.display, window->X11.handle,
			RevertToParent, CurrentTime);
	XMoveWindow(_glfwLibrary.X11.display, window->X11.handle, 0, 0);
	XResizeWindow(_glfwLibrary.X11.display, window->X11.handle,
		      window->width, window->height);
    }

    // HACK: Try to get window inside viewport (for virtual displays) by moving
    // the cursor to the upper left corner (and then to the center)
    // This hack should be harmless on saner systems as well
    XWarpPointer(_glfwLibrary.X11.display, None, window->X11.handle, 0,0,0,0, 0,0);
    XWarpPointer(_glfwLibrary.X11.display, None, window->X11.handle, 0,0,0,0,
		 window->width / 2, window->height / 2);
}
Example #30
0
int XMessageBox::show()
{
   if (mDisplay == NULL)
      return -1;

   int retVal = 0;
   retVal = loadFont();
   if (retVal < 0)
      return retVal;

   // set the maximum window dimensions
   mScreenWidth = DisplayWidth(mDisplay, DefaultScreen(mDisplay));
   mScreenHeight = DisplayHeight(mDisplay, DefaultScreen(mDisplay));
   mMaxWindowWidth = min(mScreenWidth, MessageBox_MaxWinWidth);
   mMaxWindowHeight = min(mScreenHeight, MessageBox_MaxWinHeight);

   // split the message into a vector of lines
   splitMessage();

   // set the dialog dimensions
   setDimensions();

   mWin = XCreateSimpleWindow(
      mDisplay,
      DefaultRootWindow(mDisplay),
      (mScreenWidth - mMBWidth) / 2,  (mScreenHeight - mMBHeight) / 2,
      mMBWidth, mMBHeight,
      1, 
      BlackPixel(mDisplay, DefaultScreen(mDisplay)),
      WhitePixel(mDisplay, DefaultScreen(mDisplay)));

   mGC = XCreateGC(mDisplay, mWin, 0, 0);

   XSetFont(mDisplay, mGC, mFS->fid);

   // set input mask
   XSelectInput(mDisplay, mWin, 
      ExposureMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask);

   // set wm protocols in case they hit X
   Atom wm_delete_window = 
      XInternAtom(mDisplay, "WM_DELETE_WINDOW", False);
   Atom wm_protocols = 
      XInternAtom(mDisplay, "WM_PROTOCOLS", False);
   XSetWMProtocols (mDisplay, mWin, &wm_delete_window, 1);
   // set pop up dialog hint
   XSetTransientForHint(mDisplay, mWin, mWin);
   
   // set title
   XTextProperty wtitle;
   wtitle.value = (unsigned char *)mTitle;
   wtitle.encoding = XA_STRING;
   wtitle.format = 8;
   wtitle.nitems = strlen(mTitle);
   XSetWMName(mDisplay, mWin, &wtitle);

   // show window
   XMapWindow(mDisplay, mWin);
   // move it in case some bozo window manager repositioned it
   XMoveWindow(mDisplay, mWin, 
      (mScreenWidth - mMBWidth) / 2,  (mScreenHeight - mMBHeight) / 2);
   // raise it to top
   XRaiseWindow(mDisplay, mWin);

   XMessageBoxButton* clickedButton = NULL;
   XEvent event;
   Vector<XMessageBoxButton>::iterator iter;
   bool done = false;
   while (!done)
   {
      XNextEvent(mDisplay, &event);
      switch (event.type)
      {
         case Expose:
            repaint();
            break;
         case MotionNotify:
            for (iter = mButtons.begin(); iter != mButtons.end(); ++iter)
               iter->setMouseCoordinates(event.xmotion.x, event.xmotion.y);
            break;
         case ButtonPress:
            for (iter = mButtons.begin(); iter != mButtons.end(); ++iter)
            {
               if (iter->pointInRect(event.xbutton.x, event.xbutton.y))
               {
                  iter->setMouseDown(true);
                  iter->setMouseCoordinates(event.xbutton.x, event.xbutton.y);
                  break;
               }
            }
            break;
         case ButtonRelease:
            for (iter = mButtons.begin(); iter != mButtons.end(); ++iter)
            {
               if (iter->pointInRect(event.xbutton.x, event.xbutton.y) &&
                  iter->isMouseDown())
               {
                  // we got a winner!
                  clickedButton = iter;
                  done = true;
                  break;
               }
            }
            if (clickedButton == NULL)
            {
               // user released outside a button.  clear the button states
               for (iter = mButtons.begin(); iter != mButtons.end(); ++iter)
                  iter->setMouseDown(false);
            }
            break;
         case ClientMessage:
            if (event.xclient.message_type == wm_protocols &&
               event.xclient.data.l[0] == static_cast<long>(wm_delete_window))
               done = true;
            break;
      }
      repaint();
   }

   XUnmapWindow(mDisplay, mWin);
   XDestroyWindow(mDisplay, mWin);
   XFreeGC(mDisplay, mGC);
   XFreeFont(mDisplay, mFS);

   if (clickedButton != NULL)
      return clickedButton->getClickVal();
   else
      return -1;
}