コード例 #1
0
ファイル: GrabWindow.c プロジェクト: rn10950/FVWM95-Updated
void Loop(Window target)
{
  Window root;
  int x,y,border_width,depth;
  XEvent Event;
  int tw,th;
  char *temp;
  char *prop = NULL;
  Atom actual = None;
  int actual_format;
  unsigned long nitems, bytesafter;

  while(1)
    {
      XNextEvent(dpy,&Event);
      switch(Event.type)
	{
	case Expose:
	  exposed = 1;
	  RedrawWindow(target);
	  break;
	  
	case ConfigureNotify:
	  XGetGeometry(dpy,main_win,&root,&x,&y,
		       (unsigned int *)&tw,(unsigned int *)&th,
		       (unsigned int *)&border_width,
		       (unsigned int *)&depth);
	  if((tw != Width)||(th!= Height))
	    {
	      XResizeWindow(dpy,holder_win,tw-BAR_WIDTH-PAD_WIDTH3,
			    th-BAR_WIDTH-PAD_WIDTH3);
	      Width = tw;
	      Height = th;
	      if(target_y_offset + Height - BAR_WIDTH > target_height)
		target_y_offset  = target_height - Height + BAR_WIDTH;
	      if(target_y_offset < 0)
		target_y_offset = 0;
	      if(target_x_offset < 0)
		target_x_offset = 0;
	      if(target_x_offset + Width - BAR_WIDTH > target_width)
		target_x_offset  = target_width - Width + BAR_WIDTH;

	      XMoveWindow(dpy,target,-target_x_offset, -target_y_offset);
	      exposed = 1;
	      RedrawWindow(target);
	    }
	  break;
	  
	case ButtonPress:
	  if((Event.xbutton.y > Height-BAR_WIDTH) &&
	     (Event.xbutton.x < SCROLL_BAR_WIDTH+PAD_WIDTH3))
	    {
	      motion = LEFT;
	      exposed = 2;
	      RedrawWindow(target);
	    }
	  else if((Event.xbutton.y > Height-BAR_WIDTH) &&
	     (Event.xbutton.x > Width-BAR_WIDTH-SCROLL_BAR_WIDTH-2) &&
	     (Event.xbutton.x < Width-BAR_WIDTH))
	    {
	      motion = RIGHT;
	      exposed = 2;
	      RedrawWindow(target);
	    }
	  else if((Event.xbutton.y < SCROLL_BAR_WIDTH+PAD_WIDTH3) &&
	     (Event.xbutton.x > Width-BAR_WIDTH))
	    {
	      motion = TOP;
	      exposed = 2;
	      RedrawWindow(target);
	    }
	  else if((Event.xbutton.y > Height-BAR_WIDTH-SCROLL_BAR_WIDTH-2) &&
	     (Event.xbutton.y < Height-BAR_WIDTH)&&
	     (Event.xbutton.x > Width-BAR_WIDTH))
	    {
	      motion = BOTTOM;
	      exposed = 2;
	      RedrawWindow(target);
	    }
	  else if((Event.xbutton.x > Width - BAR_WIDTH)&&
		  (Event.xbutton.y < Height- BAR_WIDTH))
	    {

	      motion = VERTICAL;
	      target_y_offset=(Event.xbutton.y-PAD_WIDTH3-SCROLL_BAR_WIDTH)*
		target_height/
		(Height-BAR_WIDTH-PAD_WIDTH3 - 2*SCROLL_BAR_WIDTH);
	      if(target_y_offset+Height-BAR_WIDTH -PAD_WIDTH3 > target_height)
		target_y_offset  = target_height - Height+BAR_WIDTH+PAD_WIDTH3;
	      if(target_y_offset < 0)
		target_y_offset = 0;
	      XMoveWindow(dpy,target,-target_x_offset, -target_y_offset);
	      RedrawWindow(target);
	    }
	  else if((Event.xbutton.y > Height- BAR_WIDTH ) &&
		  (Event.xbutton.x < Width- BAR_WIDTH))	    
	    {
	      motion=HORIZONTAL;
	      target_x_offset=(Event.xbutton.x -PAD_WIDTH3-SCROLL_BAR_WIDTH)*
		target_width/
		(Width-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH);
	      if(target_x_offset < 0)
		target_x_offset = 0;
	      
	      if(target_x_offset + Width - BAR_WIDTH -PAD_WIDTH3> target_width)
		target_x_offset  = target_width - Width + BAR_WIDTH+PAD_WIDTH3;
	      XMoveWindow(dpy,target,-target_x_offset, -target_y_offset);
	      RedrawWindow(target);
	    }
	  else if((Event.xbutton.y > Height- BAR_WIDTH ) &&
		  (Event.xbutton.x > Width- BAR_WIDTH))	    
	    {
	      exposed = 2;
	      motion=QUIT;
	    }
	  RedrawWindow(target);
	  break;

	case ButtonRelease:
	  if((Event.xbutton.y > Height- BAR_WIDTH ) &&
	    (Event.xbutton.x > Width- BAR_WIDTH)&&
	     (motion==QUIT))
	    {
	      XUnmapWindow(dpy,main_win);
	      XReparentWindow(dpy,target,Root,x,y);
	      XSync(dpy,0);
	      exit(0);
	    }
	  if((motion == LEFT)&&(Event.xbutton.y > Height-BAR_WIDTH) &&
	     (Event.xbutton.x < SCROLL_BAR_WIDTH+PAD_WIDTH3))
	    {
	      target_x_offset -= (Width-BAR_WIDTH-PAD_WIDTH2);
	      if(target_x_offset < 0)
		target_x_offset = 0;
	      XMoveWindow(dpy,target,-target_x_offset, -target_y_offset);
	      motion = NONE;
	      exposed = 2;
	    }
	  else if((motion == RIGHT)&&(Event.xbutton.y > Height-BAR_WIDTH) &&
	     (Event.xbutton.x > Width-BAR_WIDTH-SCROLL_BAR_WIDTH-2) &&
	     (Event.xbutton.x < Width-BAR_WIDTH))
	    {
	      target_x_offset += (Width-BAR_WIDTH-PAD_WIDTH2);
	      if(target_x_offset+Width-BAR_WIDTH -PAD_WIDTH3 > target_width)
		target_x_offset  = target_width - Width+BAR_WIDTH+PAD_WIDTH3;
	      XMoveWindow(dpy,target,-target_x_offset, -target_y_offset);
	      motion = NONE;
	      exposed = 2;
	    }
	  else if((motion == TOP)&&
		  (Event.xbutton.y<SCROLL_BAR_WIDTH+PAD_WIDTH3)&&
		  (Event.xbutton.x > Width-BAR_WIDTH))
	    {
	      target_y_offset -= (Height-BAR_WIDTH-PAD_WIDTH2);
	      if(target_y_offset < 0)
		target_y_offset = 0;
	      XMoveWindow(dpy,target,-target_x_offset, -target_y_offset);
	      motion = NONE;
	      exposed = 2;
	    }
	  else if((motion == BOTTOM)&&
		  (Event.xbutton.y > Height-BAR_WIDTH-SCROLL_BAR_WIDTH-2) &&
		  (Event.xbutton.y < Height-BAR_WIDTH)&&
		  (Event.xbutton.x > Width-BAR_WIDTH))
	    {
	      target_y_offset += (Height-BAR_WIDTH-PAD_WIDTH2);
	      if(target_y_offset+Height-BAR_WIDTH -PAD_WIDTH3 > target_height)
		target_y_offset  = target_height - Height+BAR_WIDTH+PAD_WIDTH3;
	      XMoveWindow(dpy,target,-target_x_offset, -target_y_offset);
	      motion = NONE;
	      exposed = 2;
	    }
	  if(motion == VERTICAL)
	    {
	      target_y_offset=(Event.xbutton.y-PAD_WIDTH3-SCROLL_BAR_WIDTH)*target_height/
		(Height-BAR_WIDTH-PAD_WIDTH3 - 2*SCROLL_BAR_WIDTH);
	      if(target_y_offset+Height-BAR_WIDTH -PAD_WIDTH3 > target_height)
		target_y_offset  = target_height - Height+BAR_WIDTH+PAD_WIDTH3;
	      if(target_y_offset < 0)
		target_y_offset = 0;
	      XMoveWindow(dpy,target,-target_x_offset, -target_y_offset);
	    }
	  if(motion == HORIZONTAL)
	    {
	      target_x_offset=(Event.xbutton.x -PAD_WIDTH3-SCROLL_BAR_WIDTH)* target_width/
		(Width-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH);
	      if(target_x_offset < 0)
		target_x_offset = 0;
	      
	      if(target_x_offset + Width - BAR_WIDTH -PAD_WIDTH3> target_width)
		target_x_offset  = target_width - Width + BAR_WIDTH+PAD_WIDTH3;
	      XMoveWindow(dpy,target,-target_x_offset, -target_y_offset);
	    }
	  RedrawWindow(target);
	  motion = NONE;
	  break;

	case MotionNotify:
	  if((motion == LEFT)&&((Event.xmotion.y < Height-BAR_WIDTH) ||
	     (Event.xmotion.x > SCROLL_BAR_WIDTH+PAD_WIDTH3)))
	    {
	      motion = NONE;
	      exposed = 2;
	    }
	  else if((motion == RIGHT)&&((Event.xmotion.y < Height-BAR_WIDTH) ||
	     (Event.xmotion.x < Width-BAR_WIDTH-SCROLL_BAR_WIDTH-2) ||
	     (Event.xmotion.x > Width-BAR_WIDTH)))
	    {
	      motion = NONE;
	      exposed = 2;
	    }
	  else if((motion == TOP)&&
		  ((Event.xmotion.y>SCROLL_BAR_WIDTH+PAD_WIDTH3)||
		   (Event.xmotion.x < Width-BAR_WIDTH)))
	    {
	      motion = NONE;
	      exposed = 2;
	    }
	  else if((motion == BOTTOM)&&
		  ((Event.xmotion.y < Height-BAR_WIDTH-SCROLL_BAR_WIDTH-2) ||
		   (Event.xmotion.y > Height-BAR_WIDTH)||
		   (Event.xmotion.x < Width-BAR_WIDTH)))
	    {
	      motion = NONE;
	      exposed = 2;
	    }
	  if(motion == VERTICAL)
	    {
	      target_y_offset=(Event.xmotion.y-PAD_WIDTH3-SCROLL_BAR_WIDTH)*
		target_height/
		(Height-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH);
	      if(target_y_offset+Height-BAR_WIDTH -PAD_WIDTH3 > target_height)
		target_y_offset  = target_height - Height+BAR_WIDTH+PAD_WIDTH3;
	      if(target_y_offset < 0)
		target_y_offset = 0;
	      XMoveWindow(dpy,target,-target_x_offset, -target_y_offset);
	    }
	  if(motion == HORIZONTAL)
	    {
	      target_x_offset=(Event.xmotion.x -PAD_WIDTH3-SCROLL_BAR_WIDTH)*
		target_width/
		(Width-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH);
	      if(target_x_offset < 0)
		target_x_offset = 0;
	      
	      if(target_x_offset + Width - BAR_WIDTH -PAD_WIDTH3> target_width)
		target_x_offset  = target_width - Width + BAR_WIDTH+PAD_WIDTH3;
	      XMoveWindow(dpy,target,-target_x_offset, -target_y_offset);
	    }
	  if((motion == QUIT)&&
	    ((Event.xbutton.y < Height- BAR_WIDTH )||
	       (Event.xbutton.x < Width- BAR_WIDTH)))
	    {
	      motion = NONE;
	      exposed = 2;
	    }
	  RedrawWindow(target);
	  break;
	case ClientMessage:
	  if ((Event.xclient.format==32) && 
	      (Event.xclient.data.l[0]==wm_del_win))
	    {
	      DeadPipe(1);
	    }
	  break;
	case PropertyNotify:
	  if(Event.xproperty.atom == XA_WM_NAME)
	    {
	      if(XFetchName(dpy, target, &temp)==0)
		temp = NULL;
	      change_window_name(temp);
	    }
	  else if (Event.xproperty.atom == XA_WM_ICON_NAME)
	    {
	      if (XGetWindowProperty (dpy,
				      target, Event.xproperty.atom, 0,
				      MAX_ICON_NAME_LEN, False, XA_STRING, 
				      &actual,&actual_format, &nitems, 
				      &bytesafter, (unsigned char **) &prop)
		  == Success && (prop != NULL))
		change_icon_name(prop);
	    }
	  else if(Event.xproperty.atom == XA_WM_HINTS)
	    {
	      XWMHints *wmhints;

	      wmhints = XGetWMHints(dpy,target);
	      XSetWMHints(dpy,main_win, wmhints);
	      XFree(wmhints);
	    }
	  else if(Event.xproperty.atom == XA_WM_NORMAL_HINTS)	  
	    {
	      /* don't do Normal Hints. They alter the size of the window */
	    }
	  else if (Event.xproperty.atom == _XA_WM_COLORMAP_WINDOWS)
	    {
	    }
	  break;
	  
	case DestroyNotify:
	  DeadPipe(1);
	  break;

	case UnmapNotify:
	  break;

	case MapNotify:
	  XMapWindow(dpy,main_win);
	  break;
	case FocusIn:
	  XSetInputFocus(dpy,target,RevertToParent,CurrentTime);
	  break;
	case ColormapNotify:
	  {
	    XWindowAttributes xwa;
	    if(XGetWindowAttributes(dpy,target, &xwa) != 0)
	      {
		XSetWindowColormap(dpy,main_win,xwa.colormap);
	      }
	  }
	  break;
	default:
	  break;
	}
    }
  return;
}
コード例 #2
0
ファイル: xegl_ctx.c プロジェクト: Jalle19/RetroArch
static bool gfx_ctx_set_video_mode(
      unsigned width, unsigned height,
      bool fullscreen)
{
   struct sigaction sa = {{0}};
   sa.sa_handler = sighandler;
   sa.sa_flags   = SA_RESTART;
   sigemptyset(&sa.sa_mask);
   sigaction(SIGINT, &sa, NULL);
   sigaction(SIGTERM, &sa, NULL);

   XVisualInfo temp = {0};
   XSetWindowAttributes swa = {0};
   XVisualInfo *vi = NULL;
   bool windowed_full = g_settings.video.windowed_fullscreen;
   bool true_full = false;
   int x_off = 0;
   int y_off = 0;

   EGLint vid;
   if (!eglGetConfigAttrib(g_egl_dpy, g_config, EGL_NATIVE_VISUAL_ID, &vid))
      goto error;

   temp.visualid = vid;

   EGLint num_visuals;
   vi = XGetVisualInfo(g_dpy, VisualIDMask, &temp, &num_visuals);
   if (!vi)
      goto error;

   swa.colormap = g_cmap = XCreateColormap(g_dpy, RootWindow(g_dpy, vi->screen),
         vi->visual, AllocNone);
   swa.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask;
   swa.override_redirect = fullscreen ? True : False;

   if (fullscreen && !windowed_full)
   {
      if (x11_enter_fullscreen(g_dpy, width, height, &g_desktop_mode))
      {
         g_should_reset_mode = true;
         true_full = true;
      }
      else
         RARCH_ERR("[X/EGL]: Entering true fullscreen failed. Will attempt windowed mode.\n");
   }

   if (g_settings.video.monitor_index)
      g_screen = g_settings.video.monitor_index - 1;

#ifdef HAVE_XINERAMA
   if (fullscreen || g_screen != 0)
   {
      unsigned new_width  = width;
      unsigned new_height = height;
      if (x11_get_xinerama_coord(g_dpy, g_screen, &x_off, &y_off, &new_width, &new_height))
         RARCH_LOG("[X/EGL]: Using Xinerama on screen #%u.\n", g_screen);
      else
         RARCH_LOG("[X/EGL]: Xinerama is not active on screen.\n");

      if (fullscreen)
      {
         width  = new_width;
         height = new_height;
      }
   }
#endif

   RARCH_LOG("[X/EGL]: X = %d, Y = %d, W = %u, H = %u.\n",
         x_off, y_off, width, height);

   g_win = XCreateWindow(g_dpy, RootWindow(g_dpy, vi->screen),
         x_off, y_off, width, height, 0,
         vi->depth, InputOutput, vi->visual, 
         CWBorderPixel | CWColormap | CWEventMask | (true_full ? CWOverrideRedirect : 0), &swa);
   XSetWindowBackground(g_dpy, g_win, 0);

   // GLES 2.0. Don't use for any other API.
   static const EGLint egl_ctx_gles_attribs[] = {
      EGL_CONTEXT_CLIENT_VERSION, 2,
      EGL_NONE,
   };

   g_egl_ctx = eglCreateContext(g_egl_dpy, g_config, EGL_NO_CONTEXT,
         (g_api == GFX_CTX_OPENGL_ES_API) ? egl_ctx_gles_attribs : NULL);

   if (!g_egl_ctx)
      goto error;

   g_egl_surf = eglCreateWindowSurface(g_egl_dpy, g_config, (EGLNativeWindowType)g_win, NULL);
   if (!g_egl_surf)
      goto error;

   if (!eglMakeCurrent(g_egl_dpy, g_egl_surf, g_egl_surf, g_egl_ctx))
      goto error;

   gfx_ctx_update_window_title(true);
   x11_set_window_attr(g_dpy, g_win);

   if (fullscreen)
      x11_hide_mouse(g_dpy, g_win);

   if (true_full)
   {
      RARCH_LOG("[GLX]: Using true fullscreen.\n");
      XMapRaised(g_dpy, g_win);
   }
   else if (fullscreen) // We attempted true fullscreen, but failed. Attempt using windowed fullscreen.
   {
      XMapRaised(g_dpy, g_win);
      RARCH_LOG("[X/EGL]: Using windowed fullscreen.\n");
      // We have to move the window to the screen we want to go fullscreen on first.
      // x_off and y_off usually get ignored in XCreateWindow().
      x11_move_window(g_dpy, g_win, x_off, y_off, width, height);
      x11_windowed_fullscreen(g_dpy, g_win);
   }
   else
   {
      XMapWindow(g_dpy, g_win);
      // If we want to map the window on a different screen, we'll have to do it by force.
      // Otherwise, we should try to let the window manager sort it out.
      // x_off and y_off usually get ignored in XCreateWindow().
      if (g_screen)
         x11_move_window(g_dpy, g_win, x_off, y_off, width, height);
   }

   XEvent event;
   XIfEvent(g_dpy, &event, egl_wait_notify, NULL);
   XSetInputFocus(g_dpy, g_win, RevertToNone, CurrentTime);

   g_quit_atom = XInternAtom(g_dpy, "WM_DELETE_WINDOW", False);
   if (g_quit_atom)
      XSetWMProtocols(g_dpy, g_win, &g_quit_atom, 1);

   gfx_ctx_swap_interval(g_interval);

   XFree(vi);
   g_has_focus = true;
   g_inited    = true;

   driver.display_type  = RARCH_DISPLAY_X11;
   driver.video_display = (uintptr_t)g_dpy;
   driver.video_window  = (uintptr_t)g_win;
   g_true_full = true_full;

   return true;

error:
   if (vi)
      XFree(vi);

   gfx_ctx_destroy();
   return false;
}
コード例 #3
0
ファイル: omapfb.c プロジェクト: Kafay/vlc
/*****************************************************************************
 * Manage: handle omapfb events
 *****************************************************************************
 * This function should be called regularly by video output thread.
 *****************************************************************************/
static int Manage( vout_thread_t *p_vout )
{
    XEvent xevent;

    while( XPending( p_vout->p_sys->p_display ) )
    {
        XNextEvent( p_vout->p_sys->p_display, &xevent );

        if( xevent.type == ButtonPress &&
            ((XButtonEvent *)&xevent)->button == Button1 )
        {
            /* detect double-clicks */
            if( ( ((XButtonEvent *)&xevent)->time -
                    p_vout->p_sys->i_time_button_last_pressed ) < 300 )
            {
                p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
            }

            p_vout->p_sys->i_time_button_last_pressed =
                        ((XButtonEvent *)&xevent)->time;
        }
        else if( xevent.type == KeyPress )
        {
            KeySym x_key_symbol;
            vlc_value_t val;

            x_key_symbol = XKeycodeToKeysym( p_vout->p_sys->p_display,
                                             xevent.xkey.keycode, 0 );

            switch( x_key_symbol )
            {
            case XK_Return:
                val.i_int = ACTIONID_PLAY_PAUSE; break;
            case XK_Escape:
                val.i_int = ACTIONID_QUIT; break;
            case XK_Down:
                val.i_int = ACTIONID_JUMP_BACKWARD_MEDIUM; break;
            case XK_Up:
                val.i_int = ACTIONID_JUMP_FORWARD_MEDIUM; break;
            case XK_Right:
                val.i_int = ACTIONID_JUMP_FORWARD_SHORT; break;
            case XK_Left:
                val.i_int = ACTIONID_JUMP_BACKWARD_SHORT; break;
            case XK_F6:
                val.i_int = ACTIONID_TOGGLE_FULLSCREEN; break;
            case XK_F7:
                val.i_int = ACTIONID_VOL_UP; break;
            case XK_F8:
                val.i_int = ACTIONID_VOL_DOWN; break;
            }
            var_SetInteger( p_vout->p_libvlc, "key-action", val.i_int );
        }
        else if( ( xevent.type == VisibilityNotify &&
                 xevent.xvisibility.state == VisibilityUnobscured ) ||
                 xevent.type == FocusIn )
        {
            p_vout->p_sys->b_video_enabled = true;
            p_vout->p_sys->p_output_picture->p->p_pixels =
                p_vout->p_sys->p_center;
            XSetInputFocus( p_vout->p_sys->p_display, p_vout->p_sys->window,
                            RevertToParent, CurrentTime );
        }
        else if( ( xevent.type == VisibilityNotify &&
                 xevent.xvisibility.state != VisibilityUnobscured ) ||
                 xevent.type == FocusOut || xevent.type == UnmapNotify )
        {
            UpdateScreen( p_vout, 0, 0,
                          p_vout->p_sys->fb_vinfo.xres,
                          p_vout->p_sys->fb_vinfo.yres,
                          p_vout->p_sys->fb_vinfo.xres,
                          p_vout->p_sys->fb_vinfo.yres,
                          OMAPFB_COLOR_RGB565 );
            p_vout->p_sys->b_video_enabled = false;
            p_vout->p_sys->p_output_picture->p->p_pixels =
                p_vout->p_sys->p_null;
         }
    }

    if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
    {
        /* Update the object variable and trigger callback */
        var_SetBool( p_vout, "fullscreen", !p_vout->b_fullscreen );

        if( p_vout->p_sys->b_embed )
            ToggleFullScreen( p_vout );
        p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
    }

    if( p_vout->i_changes & VOUT_SIZE_CHANGE )
    {
        FreePicture( p_vout, p_vout->p_sys->p_output_picture );
        if( Init( p_vout ) )
        {
            msg_Err( p_vout, "cannot reinit framebuffer screen" );
            return VLC_EGENERIC;
        }
    }


#ifdef HAVE_OSSO
    if ( p_vout->p_sys->p_octx != NULL ) {
        if ( p_vout->p_sys->i_backlight_on_counter == i_backlight_on_interval ) {
            if ( osso_display_blanking_pause( p_vout->p_sys->p_octx ) != OSSO_OK ) {
                msg_Err( p_vout, "Could not disable backlight blanking" );
        } else {
                msg_Dbg( p_vout, "Backlight blanking disabled" );
            }
            p_vout->p_sys->i_backlight_on_counter = 0;
        } else {
            p_vout->p_sys->i_backlight_on_counter ++;
        }
    }
#endif

    return VLC_SUCCESS;
}
コード例 #4
0
ファイル: Login.c プロジェクト: aosm/X11
static void
draw_it (LoginWidget w)
{
#ifdef XPM
    int i,in_frame_x,in_login_y,in_pass_y,in_width,in_height;
    int gr_line_x, gr_line_y, gr_line_w;
#endif /* XPM */

    EraseCursor (w);

#ifdef XPM
    if( (w->login.outframewidth) < 1 )
      w->login.outframewidth = 1;
    for(i=1;i<=(w->login.outframewidth);i++)
    {
      XDrawLine(XtDisplay (w), XtWindow (w), w->login.hiGC,
    		i-1,i-1,w->core.width-i,i-1);
      XDrawLine(XtDisplay (w), XtWindow (w), w->login.hiGC,
    		i-1,i-1,i-1,w->core.height-i);
      XDrawLine(XtDisplay (w), XtWindow (w), w->login.shdGC,
    		w->core.width-i,i-1,w->core.width-i,w->core.height-i);
      XDrawLine(XtDisplay (w), XtWindow (w), w->login.shdGC,
    		i-1,w->core.height-i,w->core.width-i,w->core.height-i);
    }
    
    /* make separator line */
    gr_line_x = w->login.outframewidth + w->login.logoPadding;
    gr_line_y = GREET_Y(w) + GREET_Y_INC(w);
    gr_line_w = w->core.width - 2*(w->login.outframewidth) -
        (w->login.logoWidth + 3*(w->login.logoPadding));
 
    for(i=1;i<=(w->login.sepwidth);i++)
    {
      XDrawLine(XtDisplay (w), XtWindow (w), w->login.shdGC,
        gr_line_x,           gr_line_y + i-1,
        gr_line_x+gr_line_w, gr_line_y + i-1);
      XDrawLine(XtDisplay (w), XtWindow (w), w->login.hiGC,
        gr_line_x,           gr_line_y + 2*(w->login.inframeswidth) -i,
        gr_line_x+gr_line_w, gr_line_y + 2*(w->login.inframeswidth) -i);
    }
    
    in_frame_x = LOGIN_TEXT_X(w) - w->login.inframeswidth - 3;
    in_login_y = LOGIN_Y(w) - w->login.inframeswidth - 1 - TEXT_Y_INC(w);
    in_pass_y  = PASS_Y(w) - w->login.inframeswidth - 1 - TEXT_Y_INC(w);
 
    in_width = LOGIN_W(w) - PROMPT_W(w) -
        (w->login.logoWidth + 2*(w->login.logoPadding));
    in_height = LOGIN_H(w) + w->login.inframeswidth + 2;

    for(i=1;i<=(w->login.inframeswidth);i++)
    {
      /* Make top/left sides */
      XDrawLine(XtDisplay (w), XtWindow (w), w->login.shdGC,
	in_frame_x + i-1,             in_login_y + i-1,
	in_frame_x + in_width-i,      in_login_y + i-1); 

      XDrawLine(XtDisplay (w), XtWindow (w), w->login.shdGC,
	in_frame_x + i-1,             in_login_y + i-1,
	in_frame_x + i-1,             in_login_y + in_height-i); 

      XDrawLine(XtDisplay (w), XtWindow (w), w->login.hiGC,
        in_frame_x + in_width-i,      in_login_y + i-1,
        in_frame_x + in_width-i,      in_login_y + in_height-i); 
                
      XDrawLine(XtDisplay (w), XtWindow (w), w->login.hiGC,
	in_frame_x + i-1,             in_login_y + in_height-i,
	in_frame_x + in_width-i,      in_login_y + in_height-i);

      /* Make bottom/right sides */
      XDrawLine(XtDisplay (w), XtWindow (w), w->login.shdGC,
	in_frame_x + i-1,             in_pass_y + i-1,
	in_frame_x + in_width-i,      in_pass_y + i-1); 

      XDrawLine(XtDisplay (w), XtWindow (w), w->login.shdGC,
	in_frame_x + i-1,             in_pass_y + i-1,
	in_frame_x + i-1,             in_pass_y + in_height-i); 

      XDrawLine(XtDisplay (w), XtWindow (w), w->login.hiGC,
        in_frame_x + in_width-i,      in_pass_y + i-1,
        in_frame_x + in_width-i,      in_pass_y + in_height-i); 
                
      XDrawLine(XtDisplay (w), XtWindow (w), w->login.hiGC,
	in_frame_x + i-1,             in_pass_y + in_height-i,
	in_frame_x + in_width-i,      in_pass_y + in_height-i);
    }
#endif /* XPM */

    if (GREETING(w)[0])
	    XDrawString (XtDisplay (w), XtWindow (w), w->login.greetGC,
#ifndef XPM
			GREET_X(w), GREET_Y(w),
#else
			GREET_X(w) -
                            ((w->login.logoWidth/2) + w->login.logoPadding),
                        GREET_Y(w),
#endif /* XPM */
			GREETING(w), strlen (GREETING(w)));
    XDrawString (XtDisplay (w), XtWindow (w), w->login.promptGC,
		LOGIN_X(w), LOGIN_Y(w),
		w->login.namePrompt, strlen (w->login.namePrompt));
    XDrawString (XtDisplay (w), XtWindow (w), w->login.promptGC,
		PASS_X(w), PASS_Y(w),
		w->login.passwdPrompt, strlen (w->login.passwdPrompt));
    RedrawFail (w);
    DrawName (w, 0);
    XorCursor (w);
    /*
     * The GrabKeyboard here is needed only because of
     * a bug in the R3 server -- the keyboard is grabbed on
     * the root window, and the server won't dispatch events
     * to the focus window unless the focus window is a ancestor
     * of the grab window.  Bug in server already found and fixed,
     * compatibility until at least R4.
     */
    if (XGrabKeyboard (XtDisplay (w), XtWindow (w), False, GrabModeAsync,
		       GrabModeAsync, CurrentTime) != GrabSuccess)
    {
	XSetInputFocus (XtDisplay (w), XtWindow (w),
			RevertToPointerRoot, CurrentTime);
    }
}
コード例 #5
0
ファイル: edit-box.c プロジェクト: tommie/xppaut
static void edit_box_event(void *cookie, const XEvent *ev) {
  EDIT_BOX *sb = cookie;
  int inew;
  int nn = sb->n;
  int done = 0, i;
  char ch;
  int ihot = sb->hot;
  Window wt;
  Window w = sb->win[ihot]; /* active window */
  char *s = sb->value[ihot];

  switch (ev->type) {
  case ConfigureNotify:
  case Expose:
  case MapNotify:
    expose_ebox(sb, ev->xany.window);
    break;

  case ButtonRelease:
    if (ev->xbutton.window == sb->ok) {
      if (!sb->commit_func(sb->cookie, (char *)sb->value, sb->n)) {
        edit_box_destroy(sb);
        return;
      }
    } else if (ev->xbutton.window == sb->cancel) {
      edit_box_destroy(sb);
      return;
    } else if (ev->xbutton.window == sb->reset) {
      reset_ebox(sb);
    }
    break;

  case ButtonPress:
    for (i = 0; i < nn; i++) {
      if (ev->xbutton.window == sb->win[i]) {
        XSetInputFocus(display, sb->win[i], RevertToParent, CurrentTime);
        if (i != sb->hot)
          enew_editable(sb, i, &done, &w);
        break;
      }
    }
    break;

  case EnterNotify:
    wt = ev->xcrossing.window;
    if (wt == sb->ok || wt == sb->cancel || wt == sb->reset)
      XSetWindowBorderWidth(display, wt, 2);
    break;

  case LeaveNotify:
    wt = ev->xcrossing.window;
    if (wt == sb->ok || wt == sb->cancel || wt == sb->reset)
      XSetWindowBorderWidth(display, wt, 1);
    break;

  case KeyPress:
    ch = get_key_press(ev);
    edit_window(w, &sb->pos, s, &sb->col, &done, ch);
    if (done != 0) {
      if (done == 2) {
        edit_box_destroy(sb);
        return;
      }
      inew = (sb->hot + 1) % nn;
      enew_editable(sb, inew, &done, &w);
    }
    break;
  }
}
コード例 #6
0
ファイル: menu.c プロジェクト: alepharchives/bitrig-xenocara
struct menu *
menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt,
    char *initial, int dummy,
    void (*match)(struct menu_q *, struct menu_q *, char *),
    void (*print)(struct menu *, int))
{
	struct menu_ctx		 mc;
	struct menu_q		 resultq;
	struct menu		*mi = NULL;
	XEvent			 e;
	Window			 focuswin;
	int			 evmask, focusrevert;
	int			 xsave, ysave, xcur, ycur;

	TAILQ_INIT(&resultq);

	bzero(&mc, sizeof(mc));

	xu_ptr_getpos(sc->rootwin, &mc.x, &mc.y);

	xsave = mc.x;
	ysave = mc.y;

	if (prompt == NULL) {
		evmask = MENUMASK;
		mc.promptstr[0] = '\0';
		mc.list = 1;
	} else {
		evmask = MENUMASK | KEYMASK; /* only accept keys if prompt */
		(void)snprintf(mc.promptstr, sizeof(mc.promptstr), "%s%s",
		    prompt, PROMPT_SCHAR);
		(void)snprintf(mc.dispstr, sizeof(mc.dispstr), "%s%s%s",
		    mc.promptstr, mc.searchstr, PROMPT_ECHAR);
		mc.width = font_width(sc, mc.dispstr, strlen(mc.dispstr));
		mc.hasprompt = 1;
	}

	if (initial != NULL)
		(void)strlcpy(mc.searchstr, initial, sizeof(mc.searchstr));
	else
		mc.searchstr[0] = '\0';

	mc.match = match;
	mc.print = print;
	mc.entry = mc.prev = -1;

	XMoveResizeWindow(X_Dpy, sc->menuwin, mc.x, mc.y, mc.width,
	    font_height(sc));
	XSelectInput(X_Dpy, sc->menuwin, evmask);
	XMapRaised(X_Dpy, sc->menuwin);

	if (xu_ptr_grab(sc->menuwin, MENUGRABMASK, Cursor_question) < 0) {
		XUnmapWindow(X_Dpy, sc->menuwin);
		return (NULL);
	}

	XGetInputFocus(X_Dpy, &focuswin, &focusrevert);
	XSetInputFocus(X_Dpy, sc->menuwin, RevertToPointerRoot, CurrentTime);

	/* make sure keybindings don't remove keys from the menu stream */
	XGrabKeyboard(X_Dpy, sc->menuwin, True,
	    GrabModeAsync, GrabModeAsync, CurrentTime);

	for (;;) {
		mc.changed = 0;

		XWindowEvent(X_Dpy, sc->menuwin, evmask, &e);

		switch (e.type) {
		case KeyPress:
			if ((mi = menu_handle_key(&e, &mc, menuq, &resultq))
			    != NULL)
				goto out;
			/* FALLTHROUGH */
		case Expose:
			menu_draw(sc, &mc, menuq, &resultq);
			break;
		case MotionNotify:
			menu_handle_move(&e, &mc, sc);
			break;
		case ButtonRelease:
			if ((mi = menu_handle_release(&e, &mc, sc, &resultq))
			    != NULL)
				goto out;
			break;
		default:
			break;
		}
	}
out:
	if (dummy == 0 && mi->dummy) { /* no mouse based match */
		xfree(mi);
		mi = NULL;
	}

	XSetInputFocus(X_Dpy, focuswin, focusrevert, CurrentTime);
	/* restore if user didn't move */
	xu_ptr_getpos(sc->rootwin, &xcur, &ycur);
	if (xcur == mc.x && ycur == mc.y)
		xu_ptr_setpos(sc->rootwin, xsave, ysave);
	xu_ptr_ungrab();

	XUnmapWindow(X_Dpy, sc->menuwin);
	XUngrabKeyboard(X_Dpy, CurrentTime);

	return (mi);
}
コード例 #7
0
ファイル: fspanel.c プロジェクト: hoverisk/fspanel-black
void
handle_press (int x, int y, int button)
{
	task *tk;

#ifdef PAGER
	if (y > 2 && y < WINHEIGHT - 2)
		switch_desk ((x - GRILL_WIDTH) / PAGER_BUTTON_WIDTH);
#endif

	/* clicked left grill */
	if (x < 6)
	{
		if (tb.hidden)
			tb.hidden = 0;
		else
			tb.at_top = !tb.at_top;
		move_taskbar ();
		return;
	}

	/* clicked right grill */
	if (x + TEXTPAD > WINWIDTH)
	{
		tb.hidden = !tb.hidden;
		move_taskbar ();
		return;
	}

	tk = tb.task_list;
	while (tk)
	{
		if (x > tk->pos_x && x < tk->pos_x + tk->width)
		{
			if (button == 3)	/* right-click */
			{
				toggle_shade (tk->win);
				return;
			}

			if (tk->iconified)
			{
				tk->iconified = 0;
				tk->focused = 1;
				XMapWindow (dd, tk->win);
			} else
			{
				if (tk->focused)
				{
					tk->iconified = 1;
					tk->focused = 0;
					XIconifyWindow (dd, tk->win, scr_screen);
				} else
				{
					tk->focused = 1;
					XRaiseWindow (dd, tk->win);
					XSetInputFocus (dd, tk->win, RevertToNone, CurrentTime);
				}
			}
			gui_sync ();
			gui_draw_task (tk);
		} else
		{
			if (button == 1 && tk->focused)
			{
				tk->focused = 0;
				gui_draw_task (tk);
			}
		}

		tk = tk->next;
	}
}
コード例 #8
0
/*
 * handle X11 events
 * here we handle key, mouse, repaint and window sizing events
 */
static void X11_HandleEvents(GF_VideoOutput *vout)
{
	GF_Event evt;
	Window the_window;
	XComposeStatus state;
	X11VID();
	unsigned char keybuf[32];
	XEvent xevent;

	the_window = xWindow->fullscreen ? xWindow->full_wnd : xWindow->wnd;
	XSync(xWindow->display, False);

	while (X11_Pending(xWindow->display)) {
		  XNextEvent(xWindow->display, &xevent);
		  if (xevent.xany.window!=the_window) continue;
		  switch (xevent.type) {
		    /*
		     * X11 window resized event
		     * must inform GPAC to resize os_handle wnd
		     */
		  case ConfigureNotify:
		    if ((unsigned int) xevent.xconfigure.width != xWindow->w_width
			|| (unsigned int) xevent.xconfigure.height != xWindow->w_height)
		      {
			evt.type = GF_EVENT_SIZE;
			xWindow->w_width = evt.size.width = xevent.xconfigure.width;
			xWindow->w_height = evt.size.height = xevent.xconfigure.height;
			vout->on_event(vout->evt_cbk_hdl, &evt);
		      }
		    break;
		    /*
		     * Windows need repaint
		     */
		  case Expose:
		    if (xevent.xexpose.count > 0)	break;
		    evt.type = GF_EVENT_REFRESH;
		    vout->on_event (vout->evt_cbk_hdl, &evt);
		    break;
		    
		    /* Have we been requested to quit (or another client message?) */
		  case ClientMessage:
		    if ( (xevent.xclient.format == 32) && (xevent.xclient.data.l[0] == xWindow->WM_DELETE_WINDOW) ) {
		      evt.type = GF_EVENT_QUIT;
		      vout->on_event(vout->evt_cbk_hdl, &evt);
		    }
		    break;

		  case KeyPress:
		  case KeyRelease:
		    x11_translate_key(XKeycodeToKeysym (xWindow->display, xevent.xkey.keycode, 0), &evt.key);
			evt.type = (xevent.type ==KeyPress) ? GF_EVENT_KEYDOWN : GF_EVENT_KEYUP;
			vout->on_event (vout->evt_cbk_hdl, &evt);
		    
			if (xevent.type ==KeyPress) {
				XLookupString (&xevent.xkey, (char *) keybuf, sizeof(keybuf), NULL, &state);
				if (keybuf[0]) {
					evt.character.unicode_char = keybuf[0];
					evt.type = GF_EVENT_TEXTINPUT;
					vout->on_event (vout->evt_cbk_hdl, &evt);
				}
			}
			break;
		    
		  case ButtonPress:
			  if (!xWindow->fullscreen && !xWindow->has_focus) {
				  xWindow->has_focus = 1;
				  XSetInputFocus(xWindow->display, xWindow->wnd, RevertToParent, CurrentTime);
			  }
		  case ButtonRelease:
		    //				last_mouse_move = xevent.xbutton.time;
		    evt.mouse.x = xevent.xbutton.x;
		    evt.mouse.y = xevent.xbutton.y;
			evt.type = (xevent.type == ButtonRelease) ? GF_EVENT_MOUSEUP : GF_EVENT_MOUSEDOWN;
		    
		    switch (xevent.xbutton.button) {
		    case Button1:
		      evt.mouse.button = GF_MOUSE_LEFT;
		      vout->on_event (vout->evt_cbk_hdl, &evt);
		      break;
		    case Button2:
		      evt.mouse.button = GF_MOUSE_MIDDLE;
		      vout->on_event (vout->evt_cbk_hdl, &evt);
		      break;
		    case Button3:
		      evt.mouse.button = GF_MOUSE_RIGHT;
		      vout->on_event (vout->evt_cbk_hdl, &evt);
		      break;
		    case Button4:
		      evt.type = GF_EVENT_MOUSEWHEEL;
		      evt.mouse.wheel_pos = FIX_ONE;
		      vout->on_event(vout->evt_cbk_hdl, &evt);
		      break;
		    case Button5:
		      evt.type = GF_EVENT_MOUSEWHEEL;
		      evt.mouse.wheel_pos = -FIX_ONE;
		      vout->on_event(vout->evt_cbk_hdl, &evt);
		      break;
		    }
		    if (!xWindow->fullscreen && (xevent.type==ButtonPress) ) 
		      XSetInputFocus(xWindow->display, xWindow->wnd, RevertToNone, CurrentTime);
		    break;
		    
		  case MotionNotify:
		    evt.type = GF_EVENT_MOUSEMOVE;
		    evt.mouse.x = xevent.xmotion.x;
		    evt.mouse.y = xevent.xmotion.y;
		    vout->on_event (vout->evt_cbk_hdl, &evt);
		    break;
		    
		  case PropertyNotify:
		    break;
		  case MapNotify:
		    break;
		  case CirculateNotify:
		    break;
		  case UnmapNotify:
		    break;
		  case ReparentNotify:
		    break;
		  case FocusOut:
			if (!xWindow->fullscreen) xWindow->has_focus = 0;
		    break;
		  case FocusIn:
			if (!xWindow->fullscreen) xWindow->has_focus = 1;
		    break;
		    
		  case DestroyNotify:
		      evt.type = GF_EVENT_QUIT;
		      vout->on_event(vout->evt_cbk_hdl, &evt);
		    break;
		    
		  default:
		    break;
		  }
	 }
}
コード例 #9
0
static void HandleEvents( void )
{
	XEvent event;
	qboolean dowarp = qfalse, was_focused = focus;
	int mwx = x11display.win_width / 2;
	int mwy = x11display.win_height / 2;
	char *p;
	int key = 0;
	int time = 0;

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

#ifdef WSW_EVDEV
	if( mouse_active && m_evdev_num )
	{
		evdev_read();
	}
	else
#endif
		if( mouse_active && !dgamouse )
		{
			int root_x, root_y, win_x, win_y;
			unsigned int mask;
			Window root, child;

			if( XQueryPointer( x11display.dpy, x11display.win, &root, &child,
				&root_x, &root_y, &win_x, &win_y, &mask ) )
			{
				mx += ( (int)win_x - mwx );
				my += ( (int)win_y - mwy );
				mwx = win_x;
				mwy = win_y;

				if( mx || my )
					dowarp = qtrue;

				if( ignore_one )
				{
					mx = my = 0;
					ignore_one = qfalse;
				}
			}
		}


		while( XPending( x11display.dpy ) )
		{
			XNextEvent( x11display.dpy, &event );

			switch( event.type )
			{
			case KeyPress:
				time = Sys_XTimeToSysTime(event.xkey.time);
				p = XLateKey( &event.xkey, &key );
				if( key )
					Key_Event( key, qtrue, time );
				while ( p && *p )
				{
					qwchar wc = Q_GrabWCharFromUtf8String( (const char **)&p );
					Key_CharEvent( key, wc );
				}
				break;

			case KeyRelease:
				if( repeated_press( &event ) )
					break; // don't send release events when repeating

				time = Sys_XTimeToSysTime(event.xkey.time);
				XLateKey( &event.xkey, &key );
				Key_Event( key, event.type == KeyPress, time );
				break;

			case MotionNotify:
#ifdef WSW_EVDEV
				if( mouse_active && dgamouse && !m_evdev_num )
#else
				if( mouse_active && dgamouse )
#endif
				{
					mx += event.xmotion.x_root;
					my += event.xmotion.y_root;
					if( ignore_one )
					{
						mx = my = 0;
						ignore_one = qfalse;
					}
				}
				break;

			case ButtonPress:
				if( ( cls.key_dest == key_console ) && !in_grabinconsole->integer )
					break;
#ifdef WSW_EVDEV
				if( m_evdev_num )
					break;
#endif
				time = Sys_XTimeToSysTime(event.xkey.time);
				if( event.xbutton.button == 1 ) Key_MouseEvent( K_MOUSE1, 1, time );
				else if( event.xbutton.button == 2 ) Key_MouseEvent( K_MOUSE3, 1, time );
				else if( event.xbutton.button == 3 ) Key_MouseEvent( K_MOUSE2, 1, time );
				else if( event.xbutton.button == 4 ) Key_Event( K_MWHEELUP, 1, time );
				else if( event.xbutton.button == 5 ) Key_Event( K_MWHEELDOWN, 1, time );
				else if( event.xbutton.button >= 6 && event.xbutton.button <= 10 ) Key_MouseEvent( K_MOUSE4+event.xbutton.button-6, 1, time );
				break;

			case ButtonRelease:
				if( ( cls.key_dest == key_console ) && !in_grabinconsole->integer )
					break;
#ifdef WSW_EVDEV
				if( m_evdev_num )
					break;
#endif
				time = Sys_XTimeToSysTime(event.xkey.time);
				if( event.xbutton.button == 1 ) Key_MouseEvent( K_MOUSE1, 0, time );
				else if( event.xbutton.button == 2 ) Key_MouseEvent( K_MOUSE3, 0, time );
				else if( event.xbutton.button == 3 ) Key_MouseEvent( K_MOUSE2, 0, time );
				else if( event.xbutton.button == 4 ) Key_Event( K_MWHEELUP, 0, time );
				else if( event.xbutton.button == 5 ) Key_Event( K_MWHEELDOWN, 0, time );
				else if( event.xbutton.button >= 6 && event.xbutton.button <= 10 ) Key_MouseEvent( K_MOUSE4+event.xbutton.button-6, 0, time );
				break;

			case FocusIn:
				if( x11display.ic )
					XSetICFocus(x11display.ic);
				if( !focus )
				{
					focus = qtrue;
				}
				break;

			case FocusOut:
				if( x11display.ic )
					XUnsetICFocus(x11display.ic);
				if( focus )
				{
					Key_ClearStates();
					focus = qfalse;
				}
				break;

			case ClientMessage:
				if( event.xclient.data.l[0] == x11display.wmDeleteWindow )
					Cbuf_ExecuteText( EXEC_NOW, "quit" );
				break;

			case MapNotify:
				mapped = qtrue;
				if( x11display.modeset )
				{
					if ( x11display.dpy && x11display.win )
					{
						XSetInputFocus( x11display.dpy, x11display.win, RevertToPointerRoot, CurrentTime );
						x11display.modeset = qfalse;
					}
				}
				if( input_active )
				{
					uninstall_grabs();
					install_grabs();
				}
				break;

			case ConfigureNotify:
				VID_AppActivate( qtrue, qfalse );
				break;

			case PropertyNotify:
				if( event.xproperty.window == x11display.win )
				{
					if ( event.xproperty.atom == x11display.wmState )
					{
						qboolean was_minimized = minimized;

						_X11_CheckWMSTATE();

						if( minimized != was_minimized )
						{
							// FIXME: find a better place for this?..
							CL_SoundModule_Activate( !minimized );
						}
					}
				}
				break;
			}
		}

		if( dowarp )
		{
			XWarpPointer( x11display.dpy, None, x11display.win, 0, 0, 0, 0,
				x11display.win_width/2, x11display.win_height/2 );
		}

		// set fullscreen or windowed mode upon focus in/out events if:
		//  a) lost focus in fullscreen -> windowed
		//  b) received focus -> fullscreen if a)
		if( ( focus != was_focused ) )
		{
			if( x11display.features.wmStateFullscreen )
			{
				if( !focus && Cvar_Value( "vid_fullscreen" ) )
				{
					go_fullscreen_on_focus = qtrue;
					Cbuf_ExecuteText( EXEC_APPEND, "vid_fullscreen 0\n" );
				}
				else if( focus && go_fullscreen_on_focus )
				{
					go_fullscreen_on_focus = qfalse;
					Cbuf_ExecuteText( EXEC_APPEND, "vid_fullscreen 1\n" );
				}
			}
		}
}
コード例 #10
0
ファイル: main.c プロジェクト: yugecin/evilwm
int main(int argc, char *argv[]) {
	struct sigaction act;
	int argn = 1, ret;

	{
		const char *home = getenv("HOME");
		if (home) {
			char *conffile = xmalloc(strlen(home) + sizeof(CONFIG_FILE) + 2);
			strcpy(conffile, home);
			strcat(conffile, "/" CONFIG_FILE);
			xconfig_parse_file(evilwm_options, conffile);
			free(conffile);
		}
	}
	ret = xconfig_parse_cli(evilwm_options, argc, argv, &argn);
	if (ret == XCONFIG_MISSING_ARG) {
		fprintf(stderr, "%s: missing argument to `%s'\n", argv[0], argv[argn]);
		exit(1);
	} else if (ret == XCONFIG_BAD_OPTION) {
		if (0 == strcmp(argv[argn], "-h")
				|| 0 == strcmp(argv[argn], "--help")) {
			helptext();
			exit(0);
#ifdef STDIO
		} else if (0 == strcmp(argv[argn], "-V")
				|| 0 == strcmp(argv[argn], "--version")) {
			LOG_INFO("evilwm version " VERSION "\n");
			exit(0);
#endif
		} else {
			helptext();
			exit(1);
		}
	}

	if (opt_grabmask1) grabmask1 = parse_modifiers(opt_grabmask1);
	if (opt_grabmask2) grabmask2 = parse_modifiers(opt_grabmask2);
	if (opt_altmask) altmask = parse_modifiers(opt_altmask);

	wm_exit = 0;
	act.sa_handler = handle_signal;
	sigemptyset(&act.sa_mask);
	act.sa_flags = 0;
	sigaction(SIGTERM, &act, NULL);
	sigaction(SIGINT, &act, NULL);
	sigaction(SIGHUP, &act, NULL);

	setup_display();

	event_main_loop();

	/* Quit Nicely */
	while (clients_stacking_order)
		remove_client(clients_stacking_order->data);
	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
	if (font) XFreeFont(dpy, font);
	{
		int i;
		for (i = 0; i < num_screens; i++) {
			ewmh_deinit_screen(&screens[i]);
			XFreeGC(dpy, screens[i].invert_gc);
			XInstallColormap(dpy, DefaultColormap(dpy, i));
		}
	}
	free(screens);
	XCloseDisplay(dpy);

	return 0;
}
コード例 #11
0
ファイル: X11Window.cpp プロジェクト: ronsaldo/chela
 void X11Window::SetFocus()
 {
     XSetInputFocus(display, window, RevertToNone, CurrentTime);
 }
コード例 #12
0
ファイル: AutomateXWin.C プロジェクト: ulyssesrr/carmen_lcad
// ######################################################################
void AutomateXWin::setFocus()
{
  XSetInputFocus(itsDisplay, itsWindow, RevertToNone, CurrentTime);
}
コード例 #13
0
static int config(uint32_t width, uint32_t height, uint32_t d_width,
                       uint32_t d_height, uint32_t flags, char *title,
                       uint32_t format)
{
// int screen;

// int interval, prefer_blank, allow_exp, nothing;
    unsigned int fg, bg;
    Colormap theCmap;
    XSetWindowAttributes xswa;
    unsigned long xswamask;
    const struct fmt2Xfmtentry_s *fmte = fmt2Xfmt;

#ifdef CONFIG_XF86VM
    int vm = flags & VOFLAG_MODESWITCHING;
#endif
    Flip_Flag = flags & VOFLAG_FLIPPING;
    zoomFlag = flags & VOFLAG_SWSCALE;

    old_vo_dwidth = -1;
    old_vo_dheight = -1;

    int_pause = 0;
    if (!title)
        title = "MPlayer X11 (XImage/Shm) render";

    in_format = format;
    srcW = width;
    srcH = height;

    XGetWindowAttributes(mDisplay, mRootWin, &attribs);
    depth = attribs.depth;

    if (depth != 15 && depth != 16 && depth != 24 && depth != 32)
    {
        Visual *visual;

        depth = vo_find_depth_from_visuals(mDisplay, mScreen, &visual);
    }
    if (!XMatchVisualInfo(mDisplay, mScreen, depth, DirectColor, &vinfo) ||
        (WinID > 0
         && vinfo.visualid != XVisualIDFromVisual(attribs.visual)))
        XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo);

    /* set image size (which is indeed neither the input nor output size),
       if zoom is on it will be changed during draw_slice anyway so we don't duplicate the aspect code here
     */
    image_width = (width + 7) & (~7);
    image_height = height;

#ifdef CONFIG_GUI
    if (use_gui)
        guiGetEvent(guiSetShVideo, 0);  // the GUI will set up / resize the window
    else
#endif
    {
#ifdef CONFIG_XF86VM
        if (vm)
        {
            vo_vm_switch();
        }
#endif
        bg = WhitePixel(mDisplay, mScreen);
        fg = BlackPixel(mDisplay, mScreen);

        theCmap = vo_x11_create_colormap(&vinfo);

        xswa.background_pixel = 0;
        xswa.border_pixel = 0;
        xswa.colormap = theCmap;
        xswamask = CWBackPixel | CWBorderPixel | CWColormap;

#ifdef CONFIG_XF86VM
        if (vm)
        {
            xswa.override_redirect = True;
            xswamask |= CWOverrideRedirect;
        }
#endif

            vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, vo_dwidth, vo_dheight,
                    flags, theCmap, "x11", title);
        if (WinID > 0)
            depth = vo_x11_update_geometry();

#ifdef CONFIG_XF86VM
        if (vm)
        {
            /* Grab the mouse pointer in our window */
            if (vo_grabpointer)
                XGrabPointer(mDisplay, vo_window, True, 0,
                             GrabModeAsync, GrabModeAsync,
                             vo_window, None, CurrentTime);
            XSetInputFocus(mDisplay, vo_window, RevertToNone, CurrentTime);
        }
#endif
    }

    if (myximage)
    {
        freeMyXImage();
        sws_freeContext(swsContext);
    }
    getMyXImage();

    while (fmte->mpfmt) {
      int depth = IMGFMT_RGB_DEPTH(fmte->mpfmt);
      /* bits_per_pixel in X seems to be set to 16 for 15 bit formats
         => force depth to 16 so that only the color masks are used for the format check */
      if (depth == 15)
          depth = 16;

      if (depth            == myximage->bits_per_pixel &&
          fmte->byte_order == myximage->byte_order &&
          fmte->red_mask   == myximage->red_mask   &&
          fmte->green_mask == myximage->green_mask &&
          fmte->blue_mask  == myximage->blue_mask)
        break;
      fmte++;
    }
    if (!fmte->mpfmt) {
      mp_msg(MSGT_VO, MSGL_ERR,
             "X server image format not supported, please contact the developers\n");
      return -1;
    }
    out_format = fmte->mpfmt;
    switch ((bpp = myximage->bits_per_pixel))
    {
        case 24:
            draw_alpha_fnc = draw_alpha_24;
            break;
        case 32:
            draw_alpha_fnc = draw_alpha_32;
            break;
        case 15:
        case 16:
            if (depth == 15)
                draw_alpha_fnc = draw_alpha_15;
            else
                draw_alpha_fnc = draw_alpha_16;
            break;
        default:
            draw_alpha_fnc = draw_alpha_null;
    }
    out_offset = 0;
    // for these formats conversion is currently not support and
    // we can easily "emulate" them.
    if (out_format & 64 && (IMGFMT_IS_RGB(out_format) || IMGFMT_IS_BGR(out_format))) {
      out_format &= ~64;
#ifdef WORDS_BIGENDIAN
      out_offset = 1;
#else
      out_offset = -1;
#endif
    }

    /* always allocate swsContext as size could change between frames */
    swsContext =
        sws_getContextFromCmdLine(width, height, in_format, width, height,
                                  out_format);
    if (!swsContext)
        return -1;

    dst_width = width;
    //printf( "X11 bpp: %d  color mask:  R:%lX  G:%lX  B:%lX\n",bpp,myximage->red_mask,myximage->green_mask,myximage->blue_mask );

    return 0;
}
コード例 #14
0
ファイル: afterstep.c プロジェクト: cooljeanius/AfterStep
void
CleanupScreen()
{
    int i ;

    if( Scr.Windows )
    {
        grab_server();
        destroy_aswindow_list( &(Scr.Windows), True );
        ungrab_server();
    }

	destroy_balloon_state(&TitlebarBalloons); 
	destroy_balloon_state(&MenuBalloons); 

	release_all_old_background( True );

    DestroyManagementWindows();
    CleanupColormaps();

    if( Scr.RootCanvas )
        destroy_ascanvas( &(Scr.RootCanvas) );

    XSetInputFocus (dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
	XSync (dpy, 0);

#ifdef HAVE_XINERAMA
	if (Scr.xinerama_screens)
	{
		free (Scr.xinerama_screens);
		Scr.xinerama_screens_num = 0;
		Scr.xinerama_screens = NULL;
	}
#endif /* XINERAMA */


    for( i = 0 ; i < MAX_CURSORS; ++i )
        if( Scr.standard_cursors[i] )
        {
            XFreeCursor( dpy, Scr.standard_cursors[i] );
            Scr.standard_cursors[i] = None ;
        }

    InitLook(&Scr.Look, True);
    InitFeel(&Scr.Feel, True);


    /* free display strings; can't do this in main(), because some OS's
     * don't copy the environment variables properly */
    if( Scr.display_string )
    {
        free (Scr.display_string);
        Scr.display_string = NULL ;
    }
    if( Scr.rdisplay_string )
    {
        free (Scr.rdisplay_string);
        Scr.rdisplay_string = NULL ;
    }

    if( Scr.RootBackground )
    {
        if( Scr.RootBackground->pmap )
        {
            if( Scr.wmprops->root_pixmap == Scr.RootBackground->pmap )
			{	
                set_xrootpmap_id (Scr.wmprops, None );
				set_as_background(Scr.wmprops, None );
			}
            XFreePixmap( dpy, Scr.RootBackground->pmap );
            ASSync(False);
            LOCAL_DEBUG_OUT( "root pixmap with id %lX destroyed", Scr.RootBackground->pmap );
            Scr.RootBackground->pmap = None ;
        }
        free( Scr.RootBackground );
    }
LOCAL_DEBUG_OUT("destroying image manager : %p", Scr.image_manager);
    destroy_image_manager( Scr.image_manager, False );
LOCAL_DEBUG_OUT("destroying font manager : %p", Scr.font_manager);
    destroy_font_manager( Scr.font_manager, False );

LOCAL_DEBUG_OUT("destroying visual : %p", Scr.asv);
    destroy_screen_gcs(ASDefaultScr);
	destroy_asvisual( Scr.asv, False );

LOCAL_DEBUG_OUT("selecting input mask for Root window to 0 : %s","");
	/* Must release SubstructureRedirectMask prior to releasing wm selection in
	 * destroy_wmprops() : */
	XSelectInput( dpy, Scr.Root, 0 );
	XUngrabPointer( dpy, CurrentTime );
	XUngrabButton (dpy, AnyButton, AnyModifier, Scr.Root);

LOCAL_DEBUG_OUT("destroying wmprops : %p",Scr.wmprops);
	/* this must be done at the very end !!!! */
	destroy_wmprops( Scr.wmprops, False);
LOCAL_DEBUG_OUT("screen cleanup complete.%s","");
}
コード例 #15
0
ファイル: video_output_qt.cpp プロジェクト: GiR-Zippo/bino
void video_output_qt::enter_fullscreen()
{
    if (!_fullscreen) {
#ifdef Q_OS_MAC
        _widget->stop_rendering();
#endif
        // If the container is a window, we save its geometry here so that
        // we can restore it later.
        if (!_container_is_external)
            _geom = _container_widget->geometry();
        // If the container is not yet a window, but embedded in the main window,
        // we need to make it a window now.
        if (_container_is_external)
            _container_widget->setWindowFlags(Qt::Window);
        // Determine combined geometry of the chosen screens.
        int screens = dispatch::parameters().fullscreen_screens();
        int screen_count = 0;
        QRect geom;
        for (int i = 0; i < std::min(QApplication::desktop()->screenCount(), 16); i++) {
            if (screens & (1 << i)) {
                if (geom.isNull())
                    geom = QApplication::desktop()->screenGeometry(i);
                else
                    geom = geom.united(QApplication::desktop()->screenGeometry(i));
                screen_count++;
            }
        }
        if (geom.isNull()) {
            // Use default screen
            geom = QApplication::desktop()->screenGeometry(-1);
        }
        Qt::WindowFlags new_window_flags =
            _container_widget->windowFlags()
            | Qt::FramelessWindowHint
            | Qt::WindowStaysOnTopHint;
        // In the dual and multi screen cases we need to bypass the window manager
        // on X11 because Qt does not support _NET_WM_FULLSCREEN_MONITORS, and thus
        // the window manager would always restrict the fullscreen window to one screen.
        // Note: it may be better to set _NET_WM_FULLSCREEN_MONITORS ourselves, but that
        // would also require the window manager to support this extension...
        if (screen_count > 1)
            new_window_flags |= Qt::X11BypassWindowManagerHint;
        _container_widget->setWindowFlags(new_window_flags);
        _container_widget->setWindowState(_container_widget->windowState() | Qt::WindowFullScreen);
        _container_widget->setGeometry(geom);
        _container_widget->setCursor(Qt::BlankCursor);
        _container_widget->show();
        _container_widget->raise();
        _container_widget->activateWindow();
#ifdef Q_WS_X11
        /* According to the Qt documentation, it should be sufficient to call activateWindow()
         * to make a X11 window active when using Qt::X11BypassWindowManagerHint, but this
         * does not work for me (Ubuntu 11.04 Gnome-2D desktop). This is a workaround. */
        /* Note that using X11 functions directly means that we have to link with libX11
         * explicitly; see configure.ac. */
        /* In the hope that this crap is not necessary anymore with Qt5, we continue to test
         * for Q_WS_X11, which is never defined with Qt5. */
        if (new_window_flags & Qt::X11BypassWindowManagerHint) {
            QApplication::syncX();      // just for safety; not sure if it is necessary
            XSetInputFocus(QX11Info::display(), _container_widget->winId(), RevertToParent, CurrentTime);
            XFlush(QX11Info::display());
        }
#endif
        _container_widget->grab_focus();
        // Suspend the screensaver after going fullscreen, so that our window ID
        // represents the fullscreen window. We need to have the same ID for resume.
        if (dispatch::parameters().fullscreen_inhibit_screensaver()) {
            suspend_screensaver();
            _screensaver_inhibited = true;
        }
        _fullscreen = true;
#ifdef Q_OS_MAC
        _widget->start_rendering();
#endif
    }
}
コード例 #16
0
ファイル: vo_x11.c プロジェクト: andyzsmith/mplayer
static int config(uint32_t width, uint32_t height, uint32_t d_width,
                       uint32_t d_height, uint32_t flags, char *title,
                       uint32_t format)
{
// int screen;

// int interval, prefer_blank, allow_exp, nothing;
    Colormap theCmap;
    const struct fmt2Xfmtentry_s *fmte = fmt2Xfmt;

#ifdef CONFIG_XF86VM
    int vm = flags & VOFLAG_MODESWITCHING;
#endif
    Flip_Flag = flags & VOFLAG_FLIPPING;
    zoomFlag = flags & VOFLAG_SWSCALE;

    old_vo_dwidth = -1;
    old_vo_dheight = -1;

    int_pause = 0;
    if (!title)
        title = "MPlayer X11 (XImage/Shm) render";

    in_format = format;
    srcW = width;
    srcH = height;

    XGetWindowAttributes(mDisplay, mRootWin, &attribs);
    depth = attribs.depth;

    if (depth != 15 && depth != 16 && depth != 24 && depth != 32)
    {
        Visual *visual;

        depth = vo_find_depth_from_visuals(mDisplay, mScreen, &visual);
    }
    if (!XMatchVisualInfo(mDisplay, mScreen, depth, DirectColor, &vinfo) ||
        (WinID > 0
         && vinfo.visualid != XVisualIDFromVisual(attribs.visual)))
        XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo);

    /* set image size (which is indeed neither the input nor output size),
       if zoom is on it will be changed during draw_slice anyway so we don't duplicate the aspect code here
     */
    image_width = (width + 7) & (~7);
    image_height = height;

    {
#ifdef CONFIG_XF86VM
        if (vm)
        {
            vo_vm_switch();
        }
#endif

        theCmap = vo_x11_create_colormap(&vinfo);

            vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, vo_dwidth, vo_dheight,
                    flags, theCmap, "x11", title);
        if (WinID > 0)
            depth = vo_x11_update_geometry();

#ifdef CONFIG_XF86VM
        if (vm)
        {
            /* Grab the mouse pointer in our window */
            if (vo_grabpointer)
                XGrabPointer(mDisplay, vo_window, True, 0,
                             GrabModeAsync, GrabModeAsync,
                             vo_window, None, CurrentTime);
            XSetInputFocus(mDisplay, vo_window, RevertToNone, CurrentTime);
        }
#endif
    }

    if (myximage)
    {
        freeMyXImage();
        sws_freeContext(swsContext);
    }
    getMyXImage();

    while (fmte->mpfmt) {
      int depth = IMGFMT_RGB_DEPTH(fmte->mpfmt);
      /* bits_per_pixel in X seems to be set to 16 for 15 bit formats
         => force depth to 16 so that only the color masks are used for the format check */
      if (depth == 15)
          depth = 16;

      if (depth            == myximage->bits_per_pixel &&
          fmte->byte_order == myximage->byte_order &&
          fmte->red_mask   == myximage->red_mask   &&
          fmte->green_mask == myximage->green_mask &&
          fmte->blue_mask  == myximage->blue_mask)
        break;
      fmte++;
    }
    if (!fmte->mpfmt) {
      mp_msg(MSGT_VO, MSGL_ERR,
             "X server image format not supported, please contact the developers\n");
      return -1;
    }
    out_format = fmte->mpfmt;
    draw_alpha_func = vo_get_draw_alpha(out_format);

    bpp = myximage->bits_per_pixel;
    out_offset = 0;
    // We can easily "emulate" non-native RGB32 and BGR32
    if (out_format == (IMGFMT_BGR32 | 128) || out_format == (IMGFMT_RGB32 | 128)) {
      out_format &= ~128;
#if HAVE_BIGENDIAN
      out_offset = 1;
#else
      out_offset = -1;
#endif
    }

    /* always allocate swsContext as size could change between frames */
    swsContext =
        sws_getContextFromCmdLine(width, height, in_format, width, height,
                                  out_format);
    if (!swsContext)
        return -1;

    dst_width = width;
    //printf( "X11 bpp: %d  color mask:  R:%lX  G:%lX  B:%lX\n",bpp,myximage->red_mask,myximage->green_mask,myximage->blue_mask );

    return 0;
}
コード例 #17
0
ファイル: event.c プロジェクト: xorg62/wmfs
static void
event_clientmessageevent(XEvent *e)
{
     XClientMessageEvent *ev = &e->xclient;
     struct client *c;
     struct _systray *sy;
     int type = 0;

     while(type < net_last && W->net_atom[type] != ev->message_type)
          ++type;

     /*
      * Systray message
      * _NET_WM_SYSTRAY_TRAY_OPCODE
      */
     if(ev->window == W->systray.win && type == net_system_tray_opcode)
     {
          if(ev->data.l[1] == XEMBED_EMBEDDED_NOTIFY)
          {
               systray_add(ev->data.l[2]);
               systray_update();
          }
          else if(ev->data.l[1] == XEMBED_REQUEST_FOCUS)
          {
               if((sy = systray_find(ev->data.l[2])))
                    ewmh_send_message(sy->win, sy->win, "_XEMBED", XEMBED_FOCUS_IN,
                                      XEMBED_FOCUS_CURRENT, 0, 0, 0);
          }
     }
     else if(ev->window == W->root)
     {
          /* WMFS message */
          if(ev->data.l[4])
          {
               /* Manage _WMFS_FUNCTION && _WMFS_CMD */
               if(type == wmfs_function || type == wmfs_cmd)
               {
                    Atom rt;
                    int d;
                    long unsigned int len, il;
                    unsigned char *ret = NULL, *ret_cmd = NULL;
                    void (*func)(Uicb);

                    if(XGetWindowProperty(EVDPY(e), W->root, W->net_atom[wmfs_function], 0, 65536,
                                          False, W->net_atom[utf8_string], &rt, &d,
                                          &len, &il, &ret) == Success
                       && ret && ((func = uicb_name_func((char*)ret))))
                    {
                         if(XGetWindowProperty(EVDPY(e), W->root, W->net_atom[wmfs_cmd], 0, 65536,
                                               False, W->net_atom[utf8_string], &rt, &d,
                                               &len, &il, &ret_cmd) == Success
                            && len && ret_cmd)
                         {
                              func((Uicb)ret_cmd);
                              XFree(ret_cmd);
                         }
                         else
                              func(NULL);

                         XFree(ret);
                    }
               }
          }

          if(type == net_active_window)
               if((sy = systray_find(ev->data.l[0])))
                    XSetInputFocus(W->dpy, sy->win, RevertToNone, CurrentTime);
     }

     switch(type)
     {
          /* _NET_WM_STATE */
          case net_wm_state:
               if((c = client_gb_win(ev->window)))
                    ewmh_manage_state(ev->data.l, c);
               break;
          /* _NET_CLOSE_WINDOW */
          case net_close_window:
               if((c = client_gb_win(ev->window)))
                    client_close(c);
               break;
          /* _NET_WM_DESKTOP */
          case net_wm_desktop:
               break;
     }
}
コード例 #18
0
ファイル: fg_gamemode_x11.c プロジェクト: d3x0r/SACK
void fgPlatformEnterGameMode( void ) 
{

    /*
     * Sync needed to avoid a real race, the Xserver must have really created
     * the window before we can grab the pointer into it:
     */
    XSync( fgDisplay.pDisplay.Display, False );
    /*
     * Grab the pointer to confine it into the window after the calls to
     * XWrapPointer() which ensure that the pointer really enters the window.
     *
     * We also need to wait here until XGrabPointer() returns GrabSuccess,
     * otherwise the new window is not viewable yet and if the next function
     * (XSetInputFocus) is called with a not yet viewable window, it will exit
     * the application which we have to aviod, so wait until it's viewable:
     */
    while( GrabSuccess != XGrabPointer(
               fgDisplay.pDisplay.Display, fgStructure.GameModeWindow->Window.Handle,
               TRUE,
               ButtonPressMask | ButtonReleaseMask | ButtonMotionMask
               | PointerMotionMask,
               GrabModeAsync, GrabModeAsync,
               fgStructure.GameModeWindow->Window.Handle, None, CurrentTime) )
        usleep( 100 );
    /*
     * Change input focus to the new window. This will exit the application
     * if the new window is not viewable yet, see the XGrabPointer loop above.
     */
    XSetInputFocus(
        fgDisplay.pDisplay.Display,
        fgStructure.GameModeWindow->Window.Handle,
        RevertToNone,
        CurrentTime
    );

    /* Move the Pointer to the middle of the fullscreen window */
    XWarpPointer(
        fgDisplay.pDisplay.Display,
        None,
        fgDisplay.pDisplay.RootWindow,
        0, 0, 0, 0,
        fgState.GameModeSize.X/2, fgState.GameModeSize.Y/2
    );

#   ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H

    if( fgDisplay.pDisplay.DisplayModeValid )
    {
        int x, y;
        Window child;

        /* Change to viewport to the window topleft edge: */
        if( !XF86VidModeSetViewPort( fgDisplay.pDisplay.Display, fgDisplay.pDisplay.Screen, 0, 0 ) )
            fgWarning( "XF86VidModeSetViewPort failed" );

        /*
         * Final window repositioning: It could be avoided using an undecorated
         * window using override_redirect, but this * would possily require
         * more changes and investigation.
         */

        /* Get the current postion of the drawable area on screen */
        XTranslateCoordinates(
            fgDisplay.pDisplay.Display,
            fgStructure.CurrentWindow->Window.Handle,
            fgDisplay.pDisplay.RootWindow,
            0, 0, &x, &y,
            &child
        );

        /* Move the decorataions out of the topleft corner of the display */
        XMoveWindow( fgDisplay.pDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
                     -x, -y);
    }

#endif

    /* Grab the keyboard, too */
    XGrabKeyboard(
        fgDisplay.pDisplay.Display,
        fgStructure.GameModeWindow->Window.Handle,
        FALSE,
        GrabModeAsync, GrabModeAsync,
        CurrentTime
    );

}
コード例 #19
0
/*
 * Enters the game mode
 */
int FGAPIENTRY glutEnterGameMode( void )
{
    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutEnterGameMode" );

    if( fgStructure.GameModeWindow )
        fgAddToWindowDestroyList( fgStructure.GameModeWindow );
    else
        fghRememberState( );

    if( ! fghChangeDisplayMode( GL_FALSE ) )
    {
        fgWarning( "failed to change screen settings" );
        return 0;
    }

    fgStructure.GameModeWindow = fgCreateWindow(
        NULL, "FREEGLUT", GL_TRUE, 0, 0,
        GL_TRUE, fgState.GameModeSize.X, fgState.GameModeSize.Y,
        GL_TRUE, GL_FALSE
    );

    fgStructure.GameModeWindow->State.Width  = fgState.GameModeSize.X;
    fgStructure.GameModeWindow->State.Height = fgState.GameModeSize.Y;
    fgStructure.GameModeWindow->State.NeedToResize = GL_TRUE;

#if TARGET_HOST_POSIX_X11

    /*
     * Sync needed to avoid a real race, the Xserver must have really created
     * the window before we can grab the pointer into it:
     */
    XSync( fgDisplay.Display, False );
    /*
     * Grab the pointer to confine it into the window after the calls to
     * XWrapPointer() which ensure that the pointer really enters the window.
     *
     * We also need to wait here until XGrabPointer() returns GrabSuccess,
     * otherwise the new window is not viewable yet and if the next function
     * (XSetInputFocus) is called with a not yet viewable window, it will exit
     * the application which we have to aviod, so wait until it's viewable:
     */
    while( GrabSuccess != XGrabPointer(
               fgDisplay.Display, fgStructure.GameModeWindow->Window.Handle,
               TRUE,
               ButtonPressMask | ButtonReleaseMask | ButtonMotionMask
               | PointerMotionMask,
               GrabModeAsync, GrabModeAsync,
               fgStructure.GameModeWindow->Window.Handle, None, CurrentTime) )
        usleep( 100 );
    /*
     * Change input focus to the new window. This will exit the application
     * if the new window is not viewable yet, see the XGrabPointer loop above.
     */
    XSetInputFocus(
        fgDisplay.Display,
        fgStructure.GameModeWindow->Window.Handle,
        RevertToNone,
        CurrentTime
    );

    /* Move the Pointer to the middle of the fullscreen window */
    XWarpPointer(
        fgDisplay.Display,
        None,
        fgDisplay.RootWindow,
        0, 0, 0, 0,
        fgState.GameModeSize.X/2, fgState.GameModeSize.Y/2
    );

#   ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H

    if( fgDisplay.DisplayModeValid )
    {
        int x, y;
        Window child;

        /* Change to viewport to the window topleft edge: */
        if( !XF86VidModeSetViewPort( fgDisplay.Display, fgDisplay.Screen, 0, 0 ) )
            fgWarning( "XF86VidModeSetViewPort failed" );

        /*
         * Final window repositioning: It could be avoided using an undecorated
         * window using override_redirect, but this * would possily require
         * more changes and investigation.
         */

        /* Get the current postion of the drawable area on screen */
        XTranslateCoordinates(
            fgDisplay.Display,
            fgStructure.CurrentWindow->Window.Handle,
            fgDisplay.RootWindow,
            0, 0, &x, &y,
            &child
        );

        /* Move the decorataions out of the topleft corner of the display */
        XMoveWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle,
                     -x, -y);
    }

#endif

    /* Grab the keyboard, too */
    XGrabKeyboard(
        fgDisplay.Display,
        fgStructure.GameModeWindow->Window.Handle,
        FALSE,
        GrabModeAsync, GrabModeAsync,
        CurrentTime
    );

#endif

    return fgStructure.GameModeWindow->ID;
}
コード例 #20
0
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSetInputFocus(JNIEnv *env, jclass clazz, jlong display, jlong window_ptr, jlong time) {
	Display *disp = (Display *)(intptr_t)display;
	Window window = (Window)window_ptr;
	XSetInputFocus(disp, window, RevertToParent, time);
}
コード例 #21
0
ファイル: wmswallow.c プロジェクト: d-torrance/dockapps
int main(int argc,char *argv[])
{
  int screen;
  int d_depth;
  XWMHints mywmhints;
  Pixel back_pix,fore_pix;

  int i;
  unsigned int borderwidth;
  char *wname="wmswallow";

  int remainarg, remainargc;

  XEvent Event;
  XTextProperty name;
  XClassHint classHint;

  remainarg=parseargs(argc, argv); /* remainarg > 0 afterwards */
  remainargc=argc-remainarg;
#ifdef DEBUG
  fprintf(stderr, "remainarg: %d, remainargc: %d, argc: %d\n", remainarg,
	  remainargc,argc);
  fflush(stderr);
#endif

  if (!(dpy = XOpenDisplay(display_name))) {
    fprintf(stderr,"wmswallow: can't open display %s\n",
	    XDisplayName(display_name));
    exit (1);
  }
  screen=DefaultScreen(dpy);
  Root=RootWindow(dpy, screen);

  /* So, now we've got everything we need to get Events from the XServer */
  if (remainargc>1) {
    winid=startandfind(remainargc-1, argv+remainarg+1, argv[remainarg]);
    if (winid==0) {
      perror("wmswallow: startandfind failed");
      /* Real error handling in execstuff()*/
      exit (1);
    }
  }

  d_depth=DefaultDepth(dpy, screen);
  /*   XConnectionNumber(dpy); */ /* useless */
  mysizehints.flags=USSize|USPosition;
  mysizehints.x=0;
  mysizehints.y=0;
  back_pix=GetColor("white");
  fore_pix=GetColor("black");
  XWMGeometry(dpy, screen, geometry, NULL, (borderwidth =1),
	      &mysizehints, &mysizehints.x, &mysizehints.y,
	      &mysizehints.width, &mysizehints.height, &i);
  mysizehints.width=WIDTH;
  mysizehints.height=HEIGHT;
  if (geometry!=NULL) {
#ifdef DEBUG
    fprintf(stderr,"Setting geometry to: %s\n",geometry);
    fflush(stderr);
#endif
    XParseGeometry(geometry, &mysizehints.x, &mysizehints.y,
		   &mysizehints.width, &mysizehints.height);
  }

  win=XCreateSimpleWindow(dpy, Root, mysizehints.x, mysizehints.y,
			  mysizehints.width, mysizehints.height, borderwidth,
			  fore_pix, back_pix);
  iconwin=XCreateSimpleWindow(dpy, win, mysizehints.x, mysizehints.y,
			      mysizehints.width, mysizehints.height, borderwidth,
			      fore_pix, back_pix);
  XSetWMNormalHints(dpy, win, &mysizehints);
  classHint.res_name="wmswallow";
  classHint.res_class="WMswallow";
  XSetClassHint(dpy, win, &classHint);
  XSelectInput(dpy, win, MW_EVENTS);
  XSelectInput(dpy, iconwin, MW_EVENTS);
  if(XStringListToTextProperty(&wname, 1, &name)==0)
    {
      fprintf(stderr, "wmswallow: can't allocate window name\n");
      exit(-1);
    }
  XSetWMName(dpy, win, &name);
  mywmhints.initial_state = WithdrawnState;
  mywmhints.icon_window = iconwin;
  mywmhints.icon_x = mysizehints.x;
  mywmhints.icon_y = mysizehints.y;
  mywmhints.window_group = win;
  mywmhints.flags = StateHint | IconWindowHint |
    IconPositionHint | WindowGroupHint;
  XSetWMHints(dpy, win, &mywmhints);
  XSetCommand(dpy, win, argv, argc);

  if (winid==0) {
    swallowed=findnamedwindow(argv[remainarg]); /* Find which window to
						   swallow*/
#ifdef DEBUG
    fprintf(stderr,"%s has Window-id 0x%lx\n", argv[remainarg], swallowed);
    fflush(stderr);
#endif
  }
  else
    swallowed=winid;


  /* "Swallow" it */
  XReparentWindow(dpy, swallowed, iconwin, 0, 0);
  if (getclick) {
    /* softenwindow (swallowed); */ /* Change some attributes */
    XSelectInput(dpy, swallowed, SW_EVENTS|ButtonPressMask);
  }
  else {
    XSelectInput(dpy, swallowed, SW_EVENTS); /* Workaround for apps like
						perfmeter that don't let us
						get their mouseclicks :-( */
  }
  XSetWindowBorderWidth(dpy, swallowed,0);
  XMoveResizeWindow(dpy, swallowed, 0, 0,
		    mysizehints.width, mysizehints.height);

  /* Now we do some special juju for shaped windows: */

  /* ...tell the window to repaint itself, please! */
  if (shape) {
    sendexpose(swallowed);

    /* ... ok, window should be repainted and a shaped window should have updated
       its mask accordingly! (-: End of shape-juju :-) */

    /* Now steal the shape of the Window we just swallowed! */
    stealshape(swallowed); }
  XMapWindow(dpy,win);
  XMapSubwindows(dpy,win);
  FlushWindow();

  while(1)
    {
      while (XPending(dpy))
	{
	  XNextEvent(dpy,&Event);
	  switch(Event.type)
	    {
	    case ButtonPress:
#ifdef DEBUG
	      fprintf (stderr, "wmswallow: Got ButtonPress Event\n");
	      fflush(stderr);
#endif
	      if (getclick)
		system(execstring);
	      break;
	    case Expose:
	      if(Event.xexpose.count == 0 ) {
#ifdef DEBUG
		fprintf (stderr, "wmswallow: Got Expose Event, count==0\n");
		fflush(stderr);
#endif
		if (shape)
		  stealshape(swallowed); /* Oclock changes its shape! That's why
					    we have to steal it *again* */
		FlushWindow();
	        XMapRaised(dpy,swallowed);
		/* the following Produces "focus-flicker" */
		/* XMapSubwindows(dpy,win); */
		/* XMapWindow(dpy,win); */
	      }
	      break;
	    case EnterNotify:
	      if (focus)
		XSetInputFocus(dpy, swallowed, RevertToPointerRoot,
		CurrentTime);
	      break;
	    case LeaveNotify:
	      if (focus)
		XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot,
		CurrentTime);
	      break;

	    case DestroyNotify:
	      XCloseDisplay(dpy);
	      exit(0);
	    default:
#ifdef DEBUG
	      /* fprintf (stderr, "wmswallow: Got Some Other Event\n");
			      fflush(stderr); */
#endif
	      break;
	    }
	}
      XFlush(dpy);
      usleep(50000L);
    }
  return 1;
}
コード例 #22
0
ファイル: x_ctx.c プロジェクト: meepingsnesroms/RetroArch
static bool gfx_ctx_x_set_video_mode(void *data,
      video_frame_info_t *video_info,
      unsigned width, unsigned height,
      bool fullscreen)
{
   XEvent event;
   bool true_full            = false;
   bool windowed_full        = false;
   int val                   = 0;
   int x_off                 = 0;
   int y_off                 = 0;
   XVisualInfo *vi           = NULL;
   XSetWindowAttributes swa  = {0};
   char *wm_name             = NULL;
   int (*old_handler)(Display*, XErrorEvent*) = NULL;
   gfx_ctx_x_data_t *x       = (gfx_ctx_x_data_t*)data;
   Atom net_wm_icon = XInternAtom(g_x11_dpy, "_NET_WM_ICON", False);
   Atom cardinal = XInternAtom(g_x11_dpy, "CARDINAL", False);
   settings_t *settings = config_get_ptr();
   unsigned opacity = settings->uints.video_window_opacity * ((unsigned)-1 / 100.0);

   frontend_driver_install_signal_handler();

   if (!x)
      return false;

   windowed_full = video_info->windowed_fullscreen;
   true_full = false;

   switch (x_api)
   {
      case GFX_CTX_OPENGL_API:
      case GFX_CTX_OPENGL_ES_API:
#ifdef HAVE_OPENGL
         vi = glXGetVisualFromFBConfig(g_x11_dpy, x->g_fbc);
         if (!vi)
            goto error;
#endif
         break;

      case GFX_CTX_NONE:
      default:
      {
         XVisualInfo vi_template;
         /* For default case, just try to obtain a visual from template. */
         int nvisuals = 0;

         memset(&vi_template, 0, sizeof(vi_template));
         vi_template.screen = DefaultScreen(g_x11_dpy);
         vi = XGetVisualInfo(g_x11_dpy, VisualScreenMask, &vi_template, &nvisuals);
         if (!vi || nvisuals < 1)
            goto error;
      }
      break;
   }

   swa.colormap = g_x11_cmap = XCreateColormap(g_x11_dpy,
         RootWindow(g_x11_dpy, vi->screen), vi->visual, AllocNone);
   swa.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask |
      LeaveWindowMask | EnterWindowMask |
      ButtonReleaseMask | ButtonPressMask;
   swa.override_redirect = False;

   if (fullscreen && !windowed_full)
   {
      if (x11_enter_fullscreen(video_info, g_x11_dpy, width, height))
      {
         x->g_should_reset_mode = true;
         true_full = true;
      }
      else
         RARCH_ERR("[GLX]: Entering true fullscreen failed. Will attempt windowed mode.\n");
   }

   wm_name = x11_get_wm_name(g_x11_dpy);
   if (wm_name)
   {
      RARCH_LOG("[GLX]: Window manager is %s.\n", wm_name);

      if (true_full && strcasestr(wm_name, "xfwm"))
      {
         RARCH_LOG("[GLX]: Using override-redirect workaround.\n");
         swa.override_redirect = True;
      }
      free(wm_name);
   }
   if (!x11_has_net_wm_fullscreen(g_x11_dpy) && true_full)
      swa.override_redirect = True;

   if (video_info->monitor_index)
      g_x11_screen = video_info->monitor_index - 1;

#ifdef HAVE_XINERAMA
   if (fullscreen || g_x11_screen != 0)
   {
      unsigned new_width  = width;
      unsigned new_height = height;

      if (xinerama_get_coord(g_x11_dpy, g_x11_screen,
               &x_off, &y_off, &new_width, &new_height))
         RARCH_LOG("[GLX]: Using Xinerama on screen #%u.\n", g_x11_screen);
      else
         RARCH_LOG("[GLX]: Xinerama is not active on screen.\n");

      if (fullscreen)
      {
         width  = new_width;
         height = new_height;
      }
   }
#endif

   RARCH_LOG("[GLX]: X = %d, Y = %d, W = %u, H = %u.\n",
         x_off, y_off, width, height);

   g_x11_win = XCreateWindow(g_x11_dpy, RootWindow(g_x11_dpy, vi->screen),
         x_off, y_off, width, height, 0,
         vi->depth, InputOutput, vi->visual,
         CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect,
         &swa);
   XSetWindowBackground(g_x11_dpy, g_x11_win, 0);

   XChangeProperty(g_x11_dpy, g_x11_win, net_wm_icon, cardinal, 32, PropModeReplace, (const unsigned char*)retroarch_icon_data, sizeof(retroarch_icon_data) / sizeof(*retroarch_icon_data));

   if (fullscreen && settings->bools.video_disable_composition)
   {
      uint32_t value = 1;
      Atom net_wm_bypass_compositor = XInternAtom(g_x11_dpy, "_NET_WM_BYPASS_COMPOSITOR", False);

      RARCH_LOG("[GLX]: Requesting compositor bypass.\n");
      XChangeProperty(g_x11_dpy, g_x11_win, net_wm_bypass_compositor, cardinal, 32, PropModeReplace, (const unsigned char*)&value, 1);
   }

   if (opacity < (unsigned)-1)
   {
      Atom net_wm_opacity = XInternAtom(g_x11_dpy, "_NET_WM_WINDOW_OPACITY", False);
      XChangeProperty(g_x11_dpy, g_x11_win, net_wm_opacity, cardinal, 32, PropModeReplace, (const unsigned char*)&opacity, 1);
   }

   if (!settings->bools.video_window_show_decorations)
   {
      /* We could have just set _NET_WM_WINDOW_TYPE_DOCK instead, but that removes the window from any taskbar/panel,
       * so we are forced to use the old motif hints method. */
      Hints hints;
      Atom property = XInternAtom(g_x11_dpy, "_MOTIF_WM_HINTS", False);

      hints.flags = 2;
      hints.decorations = 0;

      XChangeProperty(g_x11_dpy, g_x11_win, property, property, 32, PropModeReplace, (const unsigned char*)&hints, 5);
   }

   switch (x_api)
   {
      case GFX_CTX_OPENGL_API:
      case GFX_CTX_OPENGL_ES_API:
#ifdef HAVE_OPENGL
         x->g_glx_win = glXCreateWindow(g_x11_dpy, x->g_fbc, g_x11_win, 0);
#endif
         break;

      case GFX_CTX_NONE:
      default:
         break;
   }

   x11_set_window_attr(g_x11_dpy, g_x11_win);
   x11_update_title(NULL, video_info);

   if (fullscreen)
      x11_show_mouse(g_x11_dpy, g_x11_win, false);

   if (true_full)
   {
      RARCH_LOG("[GLX]: Using true fullscreen.\n");
      XMapRaised(g_x11_dpy, g_x11_win);
      x11_set_net_wm_fullscreen(g_x11_dpy, g_x11_win);
   }
   else if (fullscreen)
   {
      /* We attempted true fullscreen, but failed.
       * Attempt using windowed fullscreen. */

      XMapRaised(g_x11_dpy, g_x11_win);
      RARCH_LOG("[GLX]: Using windowed fullscreen.\n");

      /* We have to move the window to the screen we want
       * to go fullscreen on first.
       * x_off and y_off usually get ignored in XCreateWindow().
       */
      x11_move_window(g_x11_dpy, g_x11_win, x_off, y_off, width, height);
      x11_set_net_wm_fullscreen(g_x11_dpy, g_x11_win);
   }
   else
   {
      XMapWindow(g_x11_dpy, g_x11_win);
      /* If we want to map the window on a different screen,
       * we'll have to do it by force.
       * Otherwise, we should try to let the window manager sort it out.
       * x_off and y_off usually get ignored in XCreateWindow(). */
      if (g_x11_screen)
         x11_move_window(g_x11_dpy, g_x11_win, x_off, y_off, width, height);
   }

   x11_event_queue_check(&event);

   switch (x_api)
   {
      case GFX_CTX_OPENGL_API:
      case GFX_CTX_OPENGL_ES_API:
#ifdef HAVE_OPENGL
         if (!x->g_ctx)
         {
            if (x->g_core_es || x->g_debug)
            {
               int attribs[16];
               int *aptr = attribs;

               if (x->g_core_es)
               {
                  *aptr++ = GLX_CONTEXT_MAJOR_VERSION_ARB;
                  *aptr++ = g_major;
                  *aptr++ = GLX_CONTEXT_MINOR_VERSION_ARB;
                  *aptr++ = g_minor;

                  if (x->g_core_es_core)
                  {
                     /* Technically, we don't have core/compat until 3.2.
                      * Version 3.1 is either compat or not depending on
                      * GL_ARB_compatibility.
                      */
                     *aptr++ = GLX_CONTEXT_PROFILE_MASK_ARB;
#ifdef HAVE_OPENGLES2
                     *aptr++ = GLX_CONTEXT_ES_PROFILE_BIT_EXT;
#else
                     *aptr++ = GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
#endif
                  }
               }

               if (x->g_debug)
               {
                  *aptr++ = GLX_CONTEXT_FLAGS_ARB;
                  *aptr++ = GLX_CONTEXT_DEBUG_BIT_ARB;
               }

               *aptr = None;
               x->g_ctx = glx_create_context_attribs(g_x11_dpy,
                     x->g_fbc, NULL, True, attribs);

               if (x->g_use_hw_ctx)
               {
                  RARCH_LOG("[GLX]: Creating shared HW context.\n");
                  x->g_hw_ctx = glx_create_context_attribs(g_x11_dpy,
                        x->g_fbc, x->g_ctx, True, attribs);

                  if (!x->g_hw_ctx)
                     RARCH_ERR("[GLX]: Failed to create new shared context.\n");
               }
            }
            else
            {
               x->g_ctx = glXCreateNewContext(g_x11_dpy, x->g_fbc,
                     GLX_RGBA_TYPE, 0, True);
               if (x->g_use_hw_ctx)
               {
                  x->g_hw_ctx = glXCreateNewContext(g_x11_dpy, x->g_fbc,
                        GLX_RGBA_TYPE, x->g_ctx, True);
                  if (!x->g_hw_ctx)
                     RARCH_ERR("[GLX]: Failed to create new shared context.\n");
               }
            }

            if (!x->g_ctx)
            {
               RARCH_ERR("[GLX]: Failed to create new context.\n");
               goto error;
            }
         }
         else
         {
            video_driver_set_video_cache_context_ack();
            RARCH_LOG("[GLX]: Using cached GL context.\n");
         }

         glXMakeContextCurrent(g_x11_dpy,
               x->g_glx_win, x->g_glx_win, x->g_ctx);
#endif
         break;

      case GFX_CTX_VULKAN_API:
#ifdef HAVE_VULKAN
         {
            bool quit, resize;
            bool shutdown = false;
            unsigned width = 0, height = 0;
            x11_check_window(x, &quit, &resize, &width, &height,
                  shutdown);

            /* FIXME/TODO - threading error here */

            /* Use XCB surface since it's the most supported WSI.
             * We can obtain the XCB connection directly from X11. */
            if (!vulkan_surface_create(&x->vk, VULKAN_WSI_XCB,
                     g_x11_dpy, &g_x11_win,
                     width, height, x->g_interval))
               goto error;
         }
#endif
         break;

      case GFX_CTX_NONE:
      default:
         break;
   }

   XSync(g_x11_dpy, False);

   x11_install_quit_atom();

   switch (x_api)
   {
      case GFX_CTX_OPENGL_API:
      case GFX_CTX_OPENGL_ES_API:
#ifdef HAVE_OPENGL
         glXGetConfig(g_x11_dpy, vi, GLX_DOUBLEBUFFER, &val);
         x->g_is_double = val;

         if (x->g_is_double)
         {
            const char *swap_func = NULL;

            g_pglSwapIntervalEXT = (void (*)(Display*, GLXDrawable, int))
               glXGetProcAddress((const GLubyte*)"glXSwapIntervalEXT");
            g_pglSwapIntervalSGI = (int (*)(int))
               glXGetProcAddress((const GLubyte*)"glXSwapIntervalSGI");
            g_pglSwapInterval    = (int (*)(int))
               glXGetProcAddress((const GLubyte*)"glXSwapIntervalMESA");

            if (g_pglSwapIntervalEXT)
               swap_func = "glXSwapIntervalEXT";
            else if (g_pglSwapInterval)
               swap_func = "glXSwapIntervalMESA";
            else if (g_pglSwapIntervalSGI)
               swap_func = "glXSwapIntervalSGI";

            if (!g_pglSwapInterval && !g_pglSwapIntervalEXT && !g_pglSwapIntervalSGI)
               RARCH_WARN("[GLX]: Cannot find swap interval call.\n");
            else
               RARCH_LOG("[GLX]: Found swap function: %s.\n", swap_func);
         }
         else
            RARCH_WARN("[GLX]: Context is not double buffered!.\n");
#endif
         break;

      case GFX_CTX_NONE:
      default:
         break;
   }

   gfx_ctx_x_swap_interval(data, x->g_interval);

   /* This can blow up on some drivers.
    * It's not fatal, so override errors for this call. */
   old_handler = XSetErrorHandler(x_nul_handler);
   XSetInputFocus(g_x11_dpy, g_x11_win, RevertToNone, CurrentTime);
   XSync(g_x11_dpy, False);
   XSetErrorHandler(old_handler);

   XFree(vi);
   vi = NULL;

   if (!x11_input_ctx_new(true_full))
      goto error;

   return true;

error:
   if (vi)
      XFree(vi);

   gfx_ctx_x_destroy_resources(x);

   if (x)
      free(x);
   g_x11_screen = 0;

   return false;
}