int
window_move_resize( Display * disp, Window win, char *arg )
{                               /*{{{ */
  signed long grav, x, y, w, h;
  unsigned long grflags;
  const char *argerr = "The -e option expects a list of comma separated integers: \"gravity,X,Y,width,height\"\n";

  if ( !arg || strlen( arg ) == 0 )
  {
    fputs( argerr, stderr );
    return EXIT_FAILURE;
  }

  if ( sscanf( arg, "%ld,%ld,%ld,%ld,%ld", &grav, &x, &y, &w, &h ) != 5 )
  {
    fputs( argerr, stderr );
    return EXIT_FAILURE;
  }

  if ( grav < 0 )
  {
    fputs( "Value of gravity mustn't be negative. Use zero to use the default gravity of the window.\n", stderr );
    return EXIT_FAILURE;
  }

  grflags = grav;
  if ( x != -1 )
    grflags |= ( 1 << 8 );
  if ( y != -1 )
    grflags |= ( 1 << 9 );
  if ( w != -1 )
    grflags |= ( 1 << 10 );
  if ( h != -1 )
    grflags |= ( 1 << 11 );

  p_verbose( "grflags: %lu\n", grflags );

  if ( wm_supports( disp, "_NET_MOVERESIZE_WINDOW" ) )
  {
    return client_msg( disp, win, "_NET_MOVERESIZE_WINDOW",
                       grflags, ( unsigned long ) x, ( unsigned long ) y, ( unsigned long ) w, ( unsigned long ) h );
  }
  else
  {
    p_verbose( "WM doesn't support _NET_MOVERESIZE_WINDOW. Gravity will be ignored.\n" );
    if ( ( w < 1 || h < 1 ) && ( x >= 0 && y >= 0 ) )
    {
      XMoveWindow( disp, win, x, y );
    }
    else if ( ( x < 0 || y < 0 ) && ( w >= 1 && h >= -1 ) )
    {
      XResizeWindow( disp, win, w, h );
    }
    else if ( x >= 0 && y >= 0 && w >= 1 && h >= 1 )
    {
      XMoveResizeWindow( disp, win, x, y, w, h );
    }
    return EXIT_SUCCESS;
  }
}
示例#2
0
文件: xctrl.c 项目: ld-test/xctrl
XCTRL_API int set_window_geom(Display *disp, Window win, long grav, long x, long y, long w, long h)
{
  ulong grflags = grav;
  if (x != -1) grflags |= (1 << 8);
  if (y != -1) grflags |= (1 << 9);
  if (w != -1) grflags |= (1 << 10);
  if (h != -1) grflags |= (1 << 11);
  if (wm_supports(disp, "_NET_MOVERESIZE_WINDOW")) {
    return client_msg( disp, win, "_NET_MOVERESIZE_WINDOW", 
                       grflags, (ulong)x, (ulong)y, (ulong)w, (ulong)h);
  } else {
    if ((w < 1 || h < 1) && (x >= 0 && y >= 0)) {
      XMoveWindow(disp, win, x, y);
    } else if ((x < 0 || y < 0) && (w >= 1 && h >= -1)) {
      XResizeWindow(disp, win, w, h);
    } else if (x >= 0 && y >= 0 && w >= 1 && h >= 1) {
      XMoveResizeWindow(disp, win, x, y, w, h);
    }
    return True;
  }
}