예제 #1
0
static gchar *get_output_str(gchar *str, gboolean is_utf8)
{
    gchar *out;
   
    if(str == NULL)
        return NULL;
    
    if(envir_utf8) {
        if(is_utf8)
            out = g_strdup(str);
        
        else {
            if(!(out = g_locale_to_utf8(str, -1, NULL, NULL, NULL))) {
                p_verbose("Cannot convert string from locale charset to UTF-8.\n");
                out = g_strdup(str);
            }
        }
    }
    else {
        if(is_utf8) {
            if(!(out = g_locale_from_utf8(str, -1, NULL, NULL, NULL))) {
                p_verbose("Cannot convert string from UTF-8 to locale charset.\n");
                out = g_strdup(str);
            }
        }
        else 
            out = g_strdup(str);
    }

    return out;
}
예제 #2
0
파일: wmctrl.c 프로젝트: amkhlv/wmjump
int activate_window (Display *disp, Window win, /* {{{ */
        gboolean switch_desktop) {
    unsigned long *desktop;

    /* desktop ID */
    if ((desktop = (unsigned long *)get_property(disp, win,
            XA_CARDINAL, "_NET_WM_DESKTOP", NULL)) == NULL) {
        if ((desktop = (unsigned long *)get_property(disp, win,
                XA_CARDINAL, "_WIN_WORKSPACE", NULL)) == NULL) {
            p_verbose("Cannot find desktop ID of the window.\n");
        }
    }

    unsigned long tstamp = 0;
    tstamp = get_timestamp(disp);

    if (switch_desktop && desktop) {
        if (client_msg(disp, DefaultRootWindow(disp), 
                    "_NET_CURRENT_DESKTOP", 
                    *desktop, tstamp, 0, 0, 0) != EXIT_SUCCESS) {
            p_verbose("Cannot switch desktop.\n");
        }
        XSync(disp,FALSE);
        nanosleep(&wait_time_short,NULL);  
        g_free(desktop); desktop = NULL  ;
    }

    client_msg(disp, win, "_NET_ACTIVE_WINDOW", 0, tstamp, 0, 0, 0);
    XMapRaised(disp, win);

    /*XSync(disp,FALSE); */

    return EXIT_SUCCESS;
}/*}}}*/
예제 #3
0
파일: wndo-ctrl.c 프로젝트: wijjo/wndo
static int activate_window (Display *disp, Window win, /* {{{ */
        Bool switch_desktop) {
    CARD32 *desktop;

    /* desktop ID */
    if ((desktop = (CARD32 *)get_property(disp, win,
            XA_CARDINAL, "_NET_WM_DESKTOP", NULL)) == NULL) {
        if ((desktop = (CARD32 *)get_property(disp, win,
                XA_CARDINAL, "_WIN_WORKSPACE", NULL)) == NULL) {
            p_verbose("Cannot find desktop ID of the window.\n");
        }
    }

    if (switch_desktop && desktop) {
        if (client_msg(disp, DefaultRootWindow(disp), 
                    "_NET_CURRENT_DESKTOP", 
                    *desktop, 0, 0, 0, 0) != EXIT_SUCCESS) {
            p_verbose("Cannot switch desktop.\n");
        }
        free(desktop);
    }

    client_msg(disp, win, "_NET_ACTIVE_WINDOW", 
            0, 0, 0, 0, 0);
    XMapRaised(disp, win);

    return EXIT_SUCCESS;
}/*}}}*/
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;
  }
}
예제 #5
0
파일: wmctrl.c 프로젝트: amkhlv/wmjump
gchar *get_property (Display *disp, Window win, /*{{{*/
        Atom xa_prop_type, gchar *prop_name, unsigned long *size) {
    Atom xa_prop_name;
    Atom xa_ret_type;
    int ret_format;
    unsigned long ret_nitems;
    unsigned long ret_bytes_after;
    unsigned long tmp_size;
    unsigned char *ret_prop;
    gchar *ret;
    
    xa_prop_name = XInternAtom(disp, prop_name, False);
    
    /* MAX_PROPERTY_VALUE_LEN / 4 explanation (XGetWindowProperty manpage):
     *
     * long_length = Specifies the length in 32-bit multiples of the
     *               data to be retrieved.
     *
     * NOTE:  see 
     * http://mail.gnome.org/archives/wm-spec-list/2003-March/msg00067.html
     * In particular:
     *
     * 	When the X window system was ported to 64-bit architectures, a
     * rather peculiar design decision was made. 32-bit quantities such
     * as Window IDs, atoms, etc, were kept as longs in the client side
     * APIs, even when long was changed to 64 bits.
     *
     */
    if (XGetWindowProperty(disp, win, xa_prop_name, 0, MAX_PROPERTY_VALUE_LEN / 4, False,
            xa_prop_type, &xa_ret_type, &ret_format,     
            &ret_nitems, &ret_bytes_after, &ret_prop) != Success) {
        p_verbose("Cannot get %s property.\n", prop_name);
        return NULL;
    }
  
    if (xa_ret_type != xa_prop_type) {
        p_verbose("Invalid type of %s property.\n", prop_name);
        XFree(ret_prop);
        return NULL;
    }

    /* null terminate the result to make string handling easier */
    tmp_size = (ret_format / 8) * ret_nitems;
    /* Correct 64 Architecture implementation of 32 bit data */
    if(ret_format==32) tmp_size *= sizeof(long)/4;
    ret = g_malloc(tmp_size + 1);
    memcpy(ret, ret_prop, tmp_size);
    ret[tmp_size] = '\0';

    if (size) {
        *size = tmp_size;
    }
    
    XFree(ret_prop);
    return ret;
}/*}}}*/
예제 #6
0
파일: wndo-ctrl.c 프로젝트: wijjo/wndo
static int action_window (Display *disp, Window win, char mode) {/*{{{*/
    p_verbose("Using window: 0x%.8lx\n", win);
    switch (mode) {
        case 'a':
            return activate_window(disp, win, True);

        case 'c':
            return close_window(disp, win);

        case 'e':
            /* resize/move the window around the desktop => -r -e */
            return window_move_resize(disp, win, options.param);

        case 't':
            /* move the window to the specified desktop => -r -t */
            return window_to_desktop(disp, win, atoi(options.param));
        
        case 'R':
            /* move the window to the current desktop and activate it => -r */
            if (window_to_desktop(disp, win, -1) == EXIT_SUCCESS) {
                usleep(100000); /* 100 ms - make sure the WM has enough
                    time to move the window, before we activate it */
                return activate_window(disp, win, False);
            }
            else {
                return EXIT_FAILURE;
            }

        default:
            fprintf(stderr, "Unknown action: '%c'\n", mode);
            return EXIT_FAILURE;
    }
}/*}}}*/
gboolean
wm_supports( Display * disp, const gchar * prop )
{                               /*{{{ */
  Atom xa_prop = XInternAtom( disp, prop, False );
  Atom *list;
  unsigned long size;
  int i;

  if ( !( list = ( Atom * ) get_property( disp, DefaultRootWindow( disp ), XA_ATOM, "_NET_SUPPORTED", &size ) ) )
  {
    p_verbose( "Cannot get _NET_SUPPORTED property.\n" );
    return FALSE;
  }

  for ( i = 0; i < size / sizeof( Atom ); i++ )
  {
    if ( list[i] == xa_prop )
    {
      g_free( list );
      return TRUE;
    }
  }

  g_free( list );
  return FALSE;
}
예제 #8
0
static gchar *get_property(Display *disp, Window win,
                           Atom xa_prop_type, gchar *prop_name, 
                           unsigned long *size)
{
    Atom xa_prop_name;
    Atom xa_ret_type;
    int ret_format;
    unsigned long ret_nitems;
    unsigned long ret_bytes_after;
    unsigned long tmp_size;
    unsigned char *ret_prop;
    gchar *ret;
    
    xa_prop_name = XInternAtom(disp, prop_name, False);
    
    /* MAX_PROPERTY_VALUE_LEN / 4 explanation (XGetWindowProperty manpage):
     *
     * long_length = Specifies the length in 32-bit multiples of the
     *               data to be retrieved.
     */
    if(XGetWindowProperty(disp, win, xa_prop_name, 0, MAX_PROPERTY_VALUE_LEN / 4, False,
            xa_prop_type, &xa_ret_type, &ret_format,     
            &ret_nitems, &ret_bytes_after, &ret_prop) != Success) {
        p_verbose("Cannot get %s property.\n", prop_name);
        return NULL;
    }
  
    if(xa_ret_type != xa_prop_type) {
        p_verbose("Invalid type of %s property.\n", prop_name);
        XFree(ret_prop);
        return NULL;
    }

    /* null terminate the result to make string handling easier */
    tmp_size =(ret_format / 8) * ret_nitems;
    ret = g_malloc(tmp_size + 1);
    memcpy(ret, ret_prop, tmp_size);
    ret[tmp_size] = '\0';

    if(size)
        *size = tmp_size;
    
    XFree(ret_prop);
    return ret;
}
예제 #9
0
static void init_charset(void)
{
    const gchar *charset; /* unused */
    gchar *lang = getenv("LANG") ? g_ascii_strup(getenv("LANG"), -1) : NULL; 
    gchar *lc_ctype = getenv("LC_CTYPE") ? g_ascii_strup(getenv("LC_CTYPE"), -1) : NULL;
    
    /* this glib function doesn't work on my system ... */
    envir_utf8 = g_get_charset(&charset);

    /* ... therefore we will examine the environment variables */
    if(lc_ctype &&(strstr(lc_ctype, "UTF8") || strstr(lc_ctype, "UTF-8")))
        envir_utf8 = TRUE;
    else if(lang &&(strstr(lang, "UTF8") || strstr(lang, "UTF-8")))
        envir_utf8 = TRUE;

    g_free(lang);
    g_free(lc_ctype);
    
    if(options.force_utf8)
        envir_utf8 = TRUE;

    p_verbose("envir_utf8: %d\n", envir_utf8);
}
예제 #10
0
static int wm_info(Display *disp) {
    Window *sup_window = NULL;
    gchar *wm_name = NULL;
    gchar *wm_class = NULL;
    unsigned long *wm_pid = NULL;
    unsigned long *showing_desktop = NULL;
    gboolean name_is_utf8 = TRUE;
    gchar *name_out;
    gchar *class_out;
    
    if(!(sup_window =(Window *)get_property(disp, DefaultRootWindow(disp),
                                            XA_WINDOW, 
                                            "_NET_SUPPORTING_WM_CHECK", NULL))) {
        if(!(sup_window =(Window *)get_property(disp, DefaultRootWindow(disp),
                                                XA_CARDINAL, 
                                                "_WIN_SUPPORTING_WM_CHECK", NULL))) {
            fputs("Cannot get window manager info properties.\n"
                  "(_NET_SUPPORTING_WM_CHECK or _WIN_SUPPORTING_WM_CHECK)\n", stderr);
            return EXIT_FAILURE;
        }
    }

    /* WM_NAME */
    if(!(wm_name = get_property(disp, *sup_window,
            XInternAtom(disp, "UTF8_STRING", False), "_NET_WM_NAME", NULL))) {
        name_is_utf8 = FALSE;
        if(!(wm_name = get_property(disp, *sup_window,
                XA_STRING, "_NET_WM_NAME", NULL))) {
            p_verbose("Cannot get name of the window manager (_NET_WM_NAME).\n");
        }
    }
    name_out = get_output_str(wm_name, name_is_utf8);
  
    /* WM_CLASS */
    if(!(wm_class = get_property(disp, *sup_window,
            XInternAtom(disp, "UTF8_STRING", False), "WM_CLASS", NULL))) {
        name_is_utf8 = FALSE;
        if(!(wm_class = get_property(disp, *sup_window,
                XA_STRING, "WM_CLASS", NULL))) {
            p_verbose("Cannot get class of the window manager (WM_CLASS).\n");
        }
    }
    class_out = get_output_str(wm_class, name_is_utf8);
  

    /* WM_PID */
    if(!(wm_pid = (unsigned long *)get_property(disp, *sup_window,
                    XA_CARDINAL, "_NET_WM_PID", NULL))) {
        p_verbose("Cannot get pid of the window manager (_NET_WM_PID).\n");
    }
    
    /* _NET_SHOWING_DESKTOP */
    if(!(showing_desktop = (unsigned long *)get_property(disp, DefaultRootWindow(disp),
                    XA_CARDINAL, "_NET_SHOWING_DESKTOP", NULL))) {
        p_verbose("Cannot get the _NET_SHOWING_DESKTOP property.\n");
    }
    
    /* print out the info */
    printf("Name: %s\n", name_out ? name_out : "N/A");
    printf("Class: %s\n", class_out ? class_out : "N/A");
    
    if(wm_pid) 
        printf("PID: %lu\n", *wm_pid);
    else
        printf("PID: N/A\n");
    
    if(showing_desktop) {
        printf("Window manager's \"showing the desktop\" mode: %s\n",
                *showing_desktop == 1 ? "ON" : "OFF");
    }
    else {
        printf("Window manager's \"showing the desktop\" mode: N/A\n");
    }
    
    g_free(name_out);
    g_free(sup_window);
    g_free(wm_name);
    g_free(wm_class);
    g_free(wm_pid);
    g_free(showing_desktop);
    
    return EXIT_SUCCESS;
}
예제 #11
0
파일: main.c 프로젝트: amkhlv/wmjump
static void get_list_from_wm(   Display *disp, 
                                Window *client_list,
                                unsigned long client_list_size,
                                unsigned int *number_of_buttons,
                                int *window_number,
                                gchar **title_of_button,
                                gchar **name_of_style,
                                int groupnumber,
                                Window *win_we_leave,
                                gboolean  *win_we_leave_is_blacklisted) {

    /* Look up which window classes are blacklisted: */
    gchar *blacklist;
    gchar *file_blacklist_in_home_dir = g_strconcat(home,"/.wmjump/",BLACKLISTFILE,NULL) ;
    if ( g_file_test(file_blacklist_in_home_dir, G_FILE_TEST_EXISTS) )
        {
        g_file_get_contents( file_blacklist_in_home_dir , &blacklist,NULL,NULL);
        }
    else
        {
        g_file_get_contents( g_strconcat("/etc/wmjump/",BLACKLISTFILE,NULL) , &blacklist,NULL,NULL);
        }
    g_free(file_blacklist_in_home_dir); file_blacklist_in_home_dir = NULL ;

    unsigned long *desktop_viewport = NULL;
    *win_we_leave_is_blacklisted = TRUE ; 
    *number_of_buttons = 0;
    Window active_window = window_now_active(disp);
    *win_we_leave = active_window;
    p_verb("active window = %x\n",(int)active_window);
    /* Check if active_window is one from the client list: */
    gboolean active_window_is_strange = TRUE ;
    unsigned int i ;
    for (i = 0; i < client_list_size / sizeof(Window); i++) {
        if (active_window == client_list[i]) { active_window_is_strange = FALSE ; break ; }
        }
    if (active_window_is_strange) { p_verbose("wmjump: *** STRANGE ACTIVE WINDOW: win=%x ***\n", (int)active_window); }
    else {
        gchar *itemclass = get_window_class(disp,active_window);
        gchar *class_is_blacklisted = g_strrstr(g_strconcat("\n",blacklist,"\n",NULL),
                                                g_strconcat("\n",itemclass,"\n",NULL));
        if (class_is_blacklisted == NULL) { *win_we_leave_is_blacklisted = FALSE ; } 
         }
    
    for (i = 0; i < client_list_size / sizeof(Window); i++) {
        gchar *title_utf8 = get_window_title(disp, client_list[i]); 
        gchar *title_out = get_output_str(title_utf8, TRUE);
        
        if (verbose) printf("%d %s\n", i, title_out ? title_out : "N/A");

        gchar *itemclass = get_window_class(disp,client_list[i]);

        if (verbose) printf("window class: %s WINDOW: %x\n",itemclass,(gint)client_list[i]);
        if (verbose) printf("_______________________\n");

        gchar *class_is_blacklisted = g_strrstr(g_strconcat("\n",blacklist,"\n",NULL),
                                                g_strconcat("\n",itemclass,"\n",NULL));

        if (class_is_blacklisted == NULL) {
            unsigned long *desktop;
        
            if ((desktop = (unsigned long *)get_property(disp, client_list[i],
                    XA_CARDINAL, "_NET_WM_DESKTOP", NULL)) == NULL) {
                if ((desktop = (unsigned long *)get_property(disp, client_list[i],
                        XA_CARDINAL, "_WIN_WORKSPACE", NULL)) == NULL) {
                    printf("wmjump: Cannot find desktop ID of the window.\n"); }}

            gboolean in_scope;

            if (do_check_desktop) {
                unsigned long fake_desktop = 9999;
                unsigned long *now_desktop = &fake_desktop;
                if (given_groupnumber) {
                    unsigned long uldn = (unsigned long)groupnumber;
                    now_desktop = &uldn;
                } else {
                    if (active_window_is_strange) {
                        p_verbose("wmjump: *** COULD NOT DETECT ACTIVE WINDOW ***\n");
                    } else {
                        if ((now_desktop = (unsigned long *)get_property(
                                 disp,
                                 active_window,
                                 XA_CARDINAL,
                                 "_NET_WM_DESKTOP",
                                 NULL
                                 )) == NULL) {
                            if ((now_desktop = (unsigned long *)get_property(
                                     disp,
                                     active_window,
                                     XA_CARDINAL,
                                     "_WIN_WORKSPACE",
                                     NULL
                                     )) == NULL) {
                                printf("wmjump: Cannot find desktop ID of the window.\n");
                            }
                        }
                    }
                }
                in_scope = (*desktop == *now_desktop);
            } else {in_scope = True;}

            if ( in_scope || !current_only ) {

            int n = *number_of_buttons;
            window_number[n] = i;

            gchar desk_id[12]; /* xx,yy perhaps use some unicode instead of comma */
            sprintf(desk_id, "%d", (int)*desktop+1);
            gchar *title_tr;
            title_tr = truncate_title(title_out);
            gchar *itemtitle ;
            /* Now want to set the label string; put asterisk if active */
            gchar *lttr_bf;
            if (boldface) { lttr_bf = g_strconcat("<span weight=\"bold\">", lttr[n],
                                                  "</span>", NULL); }
            else    { lttr_bf = lttr[n]; }
            if ( client_list[i] == active_window ) {
                gchar asterisk[8];
                sprintf(asterisk, "%lc", CHECK);
                if (boldface) {
                    itemtitle = g_strconcat("<big>", asterisk, " ", desk_id," (",lttr_bf,") ",
                        "<u>",title_tr,"</u>"," (",lttr_bf,") ", asterisk, "</big>", NULL);
                                             }
                else { itemtitle = g_strconcat(asterisk, " ", desk_id," (",lttr_bf,") ",
                                        title_tr," (",lttr_bf,") ", asterisk, NULL);
                      }
            } else { 
                itemtitle = g_strconcat(desk_id," (",lttr_bf,") ",
                                        title_tr," (",lttr_bf,") ",NULL); 
            }    
            title_of_button[n]=itemtitle; 
            name_of_style[n] = itemclass ;

            (*number_of_buttons)++  ;
            if ( *number_of_buttons == g_strv_length(lttr) ) break;
            } 
            g_free(desktop);  desktop = NULL ;
            }
    }
    title_of_button[*number_of_buttons]=NULL;
    name_of_style[*number_of_buttons]=NULL;

    g_free(blacklist); blacklist = NULL ;
    g_free(desktop_viewport); desktop_viewport = NULL ;
}
예제 #12
0
//reads options and parameters from command line
void TemplateCLI::readParams(int argc, char** argv) throw (iom::exception)
{
	//command line object definition
	TCLAP::CmdLine cmd(getHelpText(), '=', "2.2.2");
		/**
		 * Command line constructor. Defines how the arguments will be
		 * parsed.
		 * \param message - The message to be used in the usage
		 * output.
		 * \param delimiter - The character that is used to separate
		 * the argument flag/name from the value.  Defaults to ' ' (space).
		 * \param version - The version number to be used in the
		 * --version switch.
		 * \param helpAndVersion - Whether or not to create the Help and
		 * Version switches. Defaults to true.
		 */


	//argument objects definitions
	//TCLAP::SwitchArg p_highest_resolution("a","all","Generate also the highest resolution.",false); 
        /**
		 * SwitchArg constructor.
		 * \param flag - The one character flag that identifies this
		 * argument on the command line.
		 * \param name - A one word name for the argument.  Can be
		 * used as a long flag on the command line.
		 * \param desc - A description of what the argument is for or
		 * does.
		 * \param def - The default value for this Switch. 
		 * \param v - An optional visitor.  You probably should not
		 * use this unless you have a very good reason.
		 */
	TCLAP::SwitchArg p_parallel("","parallel","Does not perform side-effect operations during the merge step. Use this flag when more merge steps are launched in parallel",false);
	TCLAP::SwitchArg p_isotropic("","isotropic","Generate lowest resolution with voxels as much isotropic as possible. Use this flag when the high resolution image has highy anistropic voxels",false);
	TCLAP::SwitchArg p_makedirs("","makedirs","Creates the mdata.bin file of the output volume.", false);
	TCLAP::SwitchArg p_metadata("","metadata","Creates the directory hierarchy.", false);

	TCLAP::ValueArg<std::string> p_src_root_dir("s","src","Source file / root directory path.",true,"","string");
	TCLAP::ValueArg<std::string> p_dst_root_dir("d","dst","Destination root directory path.",false,"","string");
	TCLAP::ValueArg<int> p_slice_depth("","depth","Slice depth.",false,-1,"unsigned");
	TCLAP::ValueArg<int> p_slice_height("","height","Slice height.",false,-1,"unsigned");
	TCLAP::ValueArg<int> p_slice_width("","width","Slice width.",false,-1,"unsigned");
	//TCLAP::ValueArg<string> p_src_format("","sfmt","Source format (Stacked/Simple/SimpleRaw/Raw/Tiled/TiledMC).",true,"","string");
	string temp = "Source format (\"" + 
		iim::TILED_MC_FORMAT + "\"/\"" + 
		iim::TILED_FORMAT + "\"/\"" + 
		iim::STACKED_FORMAT + "\"/\"" + 
		iim::SIMPLE_FORMAT + "\"/\"" + 
		iim::SIMPLE_RAW_FORMAT + "\"/\"" + 
		iim::RAW_FORMAT + "\"/\"" + 
		iim::TIF3D_FORMAT + "\"/\"" + 
		iim::TILED_TIF3D_FORMAT  + "\"/\"" +
		iim::TILED_MC_TIF3D_FORMAT  + "\"/\"" +
		iim::UNST_TIF3D_FORMAT  + "\")";
	TCLAP::ValueArg<string> p_src_format("","sfmt",temp.c_str(),true,"","string");
	TCLAP::ValueArg<string> p_dst_format("","dfmt","Destination format: (RGB (default)/intensity/graylevel.",false,"RGB","string");
 	//TCLAP::ValueArg<int> p_n_resolutions("","res","Number of resolutions.",true,2,"unsigned");
	TCLAP::ValueArg<std::string> p_resolutions("","resolutions","Resolutions to be produced. Possible values are [[i]...] where i = 0,..,5 and 2^i is the subsampling factor.",false,"0","string");
	TCLAP::ValueArg<string> p_halving_method("","halve","Halving method (mean/max, default: mean).",false,"mean","unsigned");
	TCLAP::ValueArg<std::string> p_outFmt("f","outFmt","Output format (Tiff2DStck/Vaa3DRaw/Tiff3D/Vaa3DRawMC/Tiff3DMC/Fiji_HDF5, default: Tiff2DStck).",false,"Tiff2DStck","string");
	TCLAP::ValueArg<std::string> p_infofile_path("","info","File path of the info log file to be saved.",false,"","string");
 	TCLAP::SwitchArg p_hide_progress_bar("","noprogressbar","Disables progress bar and estimated time remaining", false);
	TCLAP::SwitchArg p_verbose("","verbose","set verbosity to maximum level (to be activated ONLY for debugging)");
	TCLAP::ValueArg<int> p_V0("","V0","First V vertex (included).",false,-1,"unsigned");
	TCLAP::ValueArg<int> p_V1("","V1","Last V vertex (excluded).",false,-1,"unsigned");
	TCLAP::ValueArg<int> p_H0("","H0","First H vertex (included).",false,-1,"unsigned");
	TCLAP::ValueArg<int> p_H1("","H1","Last H vertex (excluded).",false,-1,"unsigned");
	TCLAP::ValueArg<int> p_D0("","D0","First D vertex (included).",false,-1,"unsigned");
	TCLAP::ValueArg<int> p_D1("","D1","Last D vertex (excluded).",false,-1,"unsigned");

	TCLAP::MultiArg<std::string> p_algo("","algorithm","Forces the use of the given algorithm.",false,"string");
	//TCLAP::SwitchArg p_pluginsinfo("p","pluginsinfo","Display plugins informations",false);
	TCLAP::ValueArg<std::string> p_vol_in_plugin("","volin_plugin",iom::strprintf("Plugin that manages the input volume format/organization. Available plugins are: {%s}. Default is \"%s\".", iom::IOPluginFactory::registeredPlugins().c_str(), vm::VOLUME_INPUT_FORMAT_PLUGIN.c_str()),false,vm::VOLUME_INPUT_FORMAT_PLUGIN,"string");
	TCLAP::ValueArg<std::string> p_vol_out_plugin("","volout_plugin",iom::strprintf("Plugin that manages the output volume format/organization. Available plugins are: {%s}. Default is \"%s\".", iom::IOPluginFactory::registeredPlugins().c_str(), vm::VOLUME_OUTPUT_FORMAT_PLUGIN.c_str()),false,vm::VOLUME_OUTPUT_FORMAT_PLUGIN,"string");
	TCLAP::ValueArg<std::string> p_im_in_plugin("","imin_plugin",iom::strprintf("Plugin that manages the input image format. Available plugins are: {%s}. Default is \"auto\".", iom::IOPluginFactory::registeredPlugins().c_str()), false, "auto","string");
	TCLAP::ValueArg<std::string> p_im_in_plugin_params("","imin_plugin_params","A series of parameters \"param1=val,param2=val,...\" to configure the input image plugin (see --pluginsinfo for the list of accepted parameters)", false, "","string");
	TCLAP::ValueArg<std::string> p_im_out_plugin("","imout_plugin",iom::strprintf("Plugin that manages the output image format. Available plugins are: {%s}. Default is \"auto\".", iom::IOPluginFactory::registeredPlugins().c_str()), false, "auto","string");
	TCLAP::ValueArg<std::string> p_im_out_plugin_params("","imout_plugin_params","A series of parameters \"param1=val,param2=val,...\" to configure the output image plugin (see --pluginsinfo for the list of accepted parameters)", false, "","string");


	//argument objects must be inserted using LIFO policy (last inserted, first shown)
	cmd.add(p_im_out_plugin_params);
	cmd.add(p_im_out_plugin);
	cmd.add(p_im_in_plugin_params);
	cmd.add(p_im_in_plugin);
	cmd.add(p_vol_out_plugin);
	cmd.add(p_vol_in_plugin);
	//cmd.add(p_pluginsinfo);
	cmd.add(p_algo);

	cmd.add(p_metadata);
    cmd.add(p_makedirs);
	cmd.add(p_parallel);
	cmd.add(p_isotropic);

	cmd.add(p_D1);
	cmd.add(p_D0);
	cmd.add(p_H1);
	cmd.add(p_H0);
	cmd.add(p_V1);
	cmd.add(p_V0);

	cmd.add(p_verbose);
	cmd.add(p_hide_progress_bar);
	cmd.add(p_infofile_path);
	cmd.add(p_outFmt);
	cmd.add(p_halving_method);
	//cmd.add(p_highest_resolution);
	//cmd.add(p_n_resolutions);
	cmd.add(p_resolutions);
	cmd.add(p_dst_format);
	cmd.add(p_src_format);
	cmd.add(p_slice_width);
	cmd.add(p_slice_height);
	cmd.add(p_slice_depth);
	cmd.add(p_dst_root_dir);
	cmd.add(p_src_root_dir);

	// Parse the argv array and catch <TCLAP> exceptions, which are translated into <iim::IOException> exceptions
	char errMsg[S_STATIC_STRINGS_SIZE];
	try{ cmd.parse( argc, argv ); } 
	catch (TCLAP::ArgException &e)
	{ 
		sprintf(errMsg, "%s for arg %s\n", e.error().c_str(), e.argId().c_str());
		throw iom::exception(errMsg);
	}

	int i;

	/* Checking parameter consistency */
	if ( p_infofile_path.getValue() == "" && p_dst_root_dir.getValue() == "" ) {
		sprintf(errMsg, "Missing destination directory (option -d)");
		throw iom::exception(errMsg);
	}

	if ( p_src_format.getValue() != iim::STACKED_FORMAT && 
		 p_src_format.getValue() != iim::SIMPLE_FORMAT  && 
		 p_src_format.getValue() != iim::SIMPLE_RAW_FORMAT  && 
		 p_src_format.getValue() != iim::RAW_FORMAT  && 
		 p_src_format.getValue() != iim::TILED_FORMAT  && 
		 p_src_format.getValue() != iim::TILED_MC_FORMAT &&
		 p_src_format.getValue() != iim::TIF3D_FORMAT  && 
		 p_src_format.getValue() != iim::TILED_TIF3D_FORMAT  && 
		 p_src_format.getValue() != iim::TILED_MC_TIF3D_FORMAT  && 
		 p_src_format.getValue() != iim::UNST_TIF3D_FORMAT ) {
		temp = "Unknown source format!\nAllowed formats are:\n\t\"" + 
			iim::TILED_MC_FORMAT + "\"/\"" + 
			iim::TILED_FORMAT + "\"/\"" + 
			iim::STACKED_FORMAT + "\"/\"" + 
			iim::SIMPLE_FORMAT + "\"/\"" + 
			iim::SIMPLE_RAW_FORMAT + "\"/\"" + 
			iim::RAW_FORMAT + "\"/\"" + 
			iim::TIF3D_FORMAT + "\"/\"" + 
			iim::TILED_TIF3D_FORMAT  + "\"/\"" +
			iim::TILED_MC_TIF3D_FORMAT  + "\"/\"" +
			iim::UNST_TIF3D_FORMAT  + "\"";
		//sprintf(errMsg, "Unknown source format!\nAllowed formats are:\n\tStacked / Simple / SimpeRaw / Raw / Tiled / TiledMC");
		sprintf(errMsg, "%s", temp.c_str());
		throw iom::exception(errMsg);
	}
	if ( p_dst_format.getValue() != "intensity" && 
		 p_dst_format.getValue() != "graylevel" && 
		 p_dst_format.getValue() != "RGB" ) {
		sprintf(errMsg, "Unknown destination format!\nAllowed formats are:\n\tintensity / graylevel / RGB");
		throw iom::exception(errMsg);
	}
	if ( p_halving_method.getValue() != "mean" && 
		 p_halving_method.getValue() != "max" ) {
		sprintf(errMsg, "Unknown halving method!\nAllowed methods are:\n\tmean / max");
		throw iom::exception(errMsg);
	}
	if ( p_outFmt.getValue() != "Tiff2DStck" && 
		 p_outFmt.getValue() != "Vaa3DRaw"   &&
		 p_outFmt.getValue() != "Tiff3D"   &&
		 p_outFmt.getValue() != "Vaa3DRawMC" &&
		 p_outFmt.getValue() != "Tiff3DMC" &&
		 p_outFmt.getValue() != "Fiji_HDF5" ) {
		sprintf(errMsg, "Unknown output format!\nAllowed formats are:\n\tTiff2DStck / Vaa3DRaw / Vaa3DRawMC / Tiff3D / Tiff3DMC / Fiji_HDF5");
		throw iom::exception(errMsg);
	}

	if ( p_outFmt.getValue() == "Fiji_HDF5" && (p_makedirs.isSet() || p_metadata.isSet() || p_parallel.isSet()) ) {
		sprintf(errMsg, "makedirs, parallel, metadata options are not allowed with Fiji_HDF5 output format");
		throw iom::exception(errMsg);
	}

	//checking that parallel-related options have been correctly selected
	if(p_makedirs.isSet() && (p_metadata.isSet() || p_parallel.isSet()) )
		throw iom::exception("parallel or metadata options cannot be set with makedirs option. See --help for usage.");

	if(p_parallel.isSet() && p_metadata.isSet() )
		throw iom::exception("metadata option cannot be set with parallel option. See --help for usage.");

	//importing parameters not set yet
	this->src_root_dir  = p_src_root_dir.getValue();
	this->dst_root_dir  = p_dst_root_dir.getValue();
	this->slice_depth   = p_slice_depth.getValue();
	this->slice_height  = p_slice_height.getValue();
	this->slice_width   = p_slice_width.getValue();
	this->src_format    = p_src_format.getValue();
	this->dst_format    = p_dst_format.getValue();
    this->metaData      = p_metadata.getValue();
    this->makeDirs      = p_makedirs.getValue();
	this->parallel      = p_parallel.getValue();
	this->isotropic     = p_isotropic.getValue();
	this->infofile_path = p_infofile_path.getValue();

	//the [algorithm] parameter is multi-arguments
	vector<string> algorithms = p_algo.getValue();
	for(int i = 0; i < algorithms.size(); i++) {
		if(algorithms[i].compare(S_NO_BLENDING_NAME) == 0)
			this->tm_blending = S_NO_BLENDING;
		else if(algorithms[i].compare(S_SINUSOIDAL_BLENDING_NAME) == 0)
			this->tm_blending = S_SINUSOIDAL_BLENDING;
		else if(algorithms[i].compare(S_SHOW_STACK_MARGIN_NAME) == 0)
			this->tm_blending = S_SHOW_STACK_MARGIN;
		else
		{
			sprintf(errMsg, "Invalid argument \"%s\" for parameter --%s! Allowed values are:\n-\"%s\"\n-\"%s\"\n",	algorithms[i].c_str(), p_algo.getName().c_str(), S_NO_BLENDING_NAME, S_SINUSOIDAL_BLENDING_NAME);
			throw iom::exception(errMsg);
		}
	}

	//this->pluginsinfo = p_pluginsinfo.getValue();

	//importing parameters
// 	vm::VOLUME_INPUT_FORMAT_PLUGIN = p_vol_in_plugin.getValue();
// 	vm::VOLUME_OUTPUT_FORMAT_PLUGIN = p_vol_out_plugin.getValue();

	// 2014-09-29. Alessandro. @ADDED automated selection of IO plugin if not provided.
// 	if(p_im_in_plugin.getValue().compare("auto") == 0)
// 	{
// 		if(vm::VOLUME_INPUT_FORMAT_PLUGIN.compare("TiledXY|2Dseries") == 0)
// 			iom::IMIN_PLUGIN = "tiff2D";
// 		else if(vm::VOLUME_INPUT_FORMAT_PLUGIN.compare("TiledXY|3Dseries") == 0)
// 			iom::IMIN_PLUGIN = "tiff3D";
// 	}
// 	else
// 		iom::IMIN_PLUGIN = p_im_in_plugin.getValue();
// 	iom::IMIN_PLUGIN_PARAMS = p_im_in_plugin_params.getValue();

	// 2014-09-29. Alessandro. @ADDED automated selection of IO plugin if not provided.
// 	if(p_im_out_plugin.getValue().compare("auto") == 0)
// 	{
// 		if(p_vol_out_plugin.getValue().compare("TiledXY|2Dseries") == 0)
// 			iom::IMOUT_PLUGIN = "tiff2D";
// 		else if(p_vol_out_plugin.getValue().compare("TiledXY|3Dseries") == 0)
// 			iom::IMOUT_PLUGIN = "tiff3D";
// 	}
// 	else
// 		iom::IMOUT_PLUGIN = p_im_in_plugin.getValue();
// 	iom::IMOUT_PLUGIN_PARAMS = p_im_out_plugin_params.getValue();

	//this->resolutions[0] = p_highest_resolution.getValue() ? 1 : 0;
	//for ( i=1; i<p_n_resolutions.getValue(); i++ )
	//	this->resolutions[i] = 1;
	//for ( ; i<S_MAX_MULTIRES; i++ )
	//	this->resolutions[i] = 0;
	for(i=0; i<= S_MAX_MULTIRES; i++) {
		stringstream buf;
		buf << i;
		this->resolutions[i] = p_resolutions.getValue().find(buf.str()) != std::string::npos;
	}

	if ( p_halving_method.getValue() == "mean" )
		this->halving_method = HALVE_BY_MEAN;
	else if ( p_halving_method.getValue() == "max" )
		this->halving_method = HALVE_BY_MAX;

	this->outFmt = p_outFmt.getValue();
	this->show_progress_bar = !p_hide_progress_bar.getValue();

	this->V0  = p_V0.getValue();
	this->V1  = p_V1.getValue();
	this->H0  = p_H0.getValue();
	this->H1  = p_H1.getValue();
	this->D0  = p_D0.getValue();
	this->D1  = p_D1.getValue();

	if(p_verbose.getValue())
	{
		terastitcher::DEBUG = terastitcher::LEV_MAX;
		iim::DEBUG = iim::LEV_MAX;
		iom::DEBUG = iom::LEV_MAX;
	}
}
예제 #13
0
파일: wmctrl.c 프로젝트: amkhlv/wmjump
int list_desktops (Display *disp) {/*{{{*/
    unsigned long *num_desktops = NULL;
    unsigned long *cur_desktop = NULL;
    unsigned long desktop_list_size = 0;
    unsigned long *desktop_geometry = NULL;
    unsigned long desktop_geometry_size = 0;
    gchar **desktop_geometry_str = NULL;
    unsigned long *desktop_viewport = NULL;
    unsigned long desktop_viewport_size = 0;
    gchar **desktop_viewport_str = NULL;
    unsigned long *desktop_workarea = NULL;
    unsigned long desktop_workarea_size = 0;
    gchar **desktop_workarea_str = NULL;
    gchar *list = NULL;
    unsigned int i;
    unsigned int id;
    Window root = DefaultRootWindow(disp);
    int ret = EXIT_FAILURE;
    gchar **names = NULL;
    gboolean names_are_utf8 = TRUE;
    
    if (! (num_desktops = (unsigned long *)get_property(disp, root,
            XA_CARDINAL, "_NET_NUMBER_OF_DESKTOPS", NULL))) {
        if (! (num_desktops = (unsigned long *)get_property(disp, root,
                XA_CARDINAL, "_WIN_WORKSPACE_COUNT", NULL))) {
            fputs("Cannot get number of desktops properties. "
                  "(_NET_NUMBER_OF_DESKTOPS or _WIN_WORKSPACE_COUNT)"
                  "\n", stderr);
            goto cleanup;
        }
    }
    
    if (! (cur_desktop = (unsigned long *)get_property(disp, root,
            XA_CARDINAL, "_NET_CURRENT_DESKTOP", NULL))) {
        if (! (cur_desktop = (unsigned long *)get_property(disp, root,
                XA_CARDINAL, "_WIN_WORKSPACE", NULL))) {
            fputs("Cannot get current desktop properties. "
                  "(_NET_CURRENT_DESKTOP or _WIN_WORKSPACE property)"
                  "\n", stderr);
            goto cleanup;
        }
    }

    if (options.wa_desktop_titles_invalid_utf8 || 
            (list = get_property(disp, root, 
            XInternAtom(disp, "UTF8_STRING", False), 
            "_NET_DESKTOP_NAMES", &desktop_list_size)) == NULL) {
        names_are_utf8 = FALSE;
        if ((list = get_property(disp, root, 
            XA_STRING, 
            "_WIN_WORKSPACE_NAMES", &desktop_list_size)) == NULL) {
            p_verbose("Cannot get desktop names properties. "
                  "(_NET_DESKTOP_NAMES or _WIN_WORKSPACE_NAMES)"
                  "\n");
            /* ignore the error - list the desktops without names */
        }
    }
 
    /* common size of all desktops */
    if (! (desktop_geometry = (unsigned long *)get_property(disp, DefaultRootWindow(disp),
                    XA_CARDINAL, "_NET_DESKTOP_GEOMETRY", &desktop_geometry_size))) {
        p_verbose("Cannot get common size of all desktops (_NET_DESKTOP_GEOMETRY).\n");
    }
     
    /* desktop viewport */
    if (! (desktop_viewport = (unsigned long *)get_property(disp, DefaultRootWindow(disp),
                    XA_CARDINAL, "_NET_DESKTOP_VIEWPORT", &desktop_viewport_size))) {
        p_verbose("Cannot get common size of all desktops (_NET_DESKTOP_VIEWPORT).\n");
    }
     
    /* desktop workarea */
    if (! (desktop_workarea = (unsigned long *)get_property(disp, DefaultRootWindow(disp),
                    XA_CARDINAL, "_NET_WORKAREA", &desktop_workarea_size))) {
        if (! (desktop_workarea = (unsigned long *)get_property(disp, DefaultRootWindow(disp),
                        XA_CARDINAL, "_WIN_WORKAREA", &desktop_workarea_size))) {
            p_verbose("Cannot get _NET_WORKAREA property.\n");
        }
    }
     
    /* prepare the array of desktop names */
    names = g_malloc0(*num_desktops * sizeof(char *));
    if (list) {
        id = 0;
        names[id++] = list;
        for (i = 0; i < desktop_list_size; i++) {
            if (list[i] == '\0') {
                if (id >= *num_desktops) {
                    break;
                }
                names[id++] = list + i + 1;
            }
        }
    }

    /* prepare desktop geometry strings */
    desktop_geometry_str = g_malloc0((*num_desktops + 1) * sizeof(char *));
    if (desktop_geometry && desktop_geometry_size > 0) {
        if (desktop_geometry_size == 2 * sizeof(*desktop_geometry)) {
            /* only one value - use it for all desktops */
            p_verbose("WM provides _NET_DESKTOP_GEOMETRY value common for all desktops.\n");
            for (i = 0; i < *num_desktops; i++) {
                desktop_geometry_str[i] = g_strdup_printf("%lux%lu", 
                desktop_geometry[0], desktop_geometry[1]);
            }
        }
        else {
            /* seperate values for desktops of different size */
            p_verbose("WM provides separate _NET_DESKTOP_GEOMETRY value for each desktop.\n");
            for (i = 0; i < *num_desktops; i++) {
                if (i < desktop_geometry_size / sizeof(*desktop_geometry) / 2) {
                    desktop_geometry_str[i] = g_strdup_printf("%lux%lu", 
                        desktop_geometry[i*2], desktop_geometry[i*2+1]);
                }
                else {
                    desktop_geometry_str[i] = g_strdup("N/A");
                }
            }
        }
    }
    else {
        for (i = 0; i < *num_desktops; i++) {
            desktop_geometry_str[i] = g_strdup("N/A");
        }
    }
 
    /* prepare desktop viewport strings */
    desktop_viewport_str = g_malloc0((*num_desktops + 1) * sizeof(char *));
    if (desktop_viewport && desktop_viewport_size > 0) {
        if (desktop_viewport_size == 2 * sizeof(*desktop_viewport)) {
            /* only one value - use it for current desktop */
            p_verbose("WM provides _NET_DESKTOP_VIEWPORT value only for the current desktop.\n");
            for (i = 0; i < *num_desktops; i++) {
                if (i == *cur_desktop) {
                    desktop_viewport_str[i] = g_strdup_printf("%lu,%lu", 
                        desktop_viewport[0], desktop_viewport[1]);
                }
                else {
                    desktop_viewport_str[i] = g_strdup("N/A");
                }
            }
        }
        else {
            /* seperate values for each of desktops */
            for (i = 0; i < *num_desktops; i++) {
                if (i < desktop_viewport_size / sizeof(*desktop_viewport) / 2) {
                    desktop_viewport_str[i] = g_strdup_printf("%lu,%lu", 
                        desktop_viewport[i*2], desktop_viewport[i*2+1]);
                }
                else {
                    desktop_viewport_str[i] = g_strdup("N/A");
                }
            }
        }
    }
    else {
        for (i = 0; i < *num_desktops; i++) {
            desktop_viewport_str[i] = g_strdup("N/A");
        }
    }
 
    /* prepare desktop workarea strings */
    desktop_workarea_str = g_malloc0((*num_desktops + 1) * sizeof(char *));
    if (desktop_workarea && desktop_workarea_size > 0) {
        if (desktop_workarea_size == 4 * sizeof(*desktop_workarea)) {
            /* only one value - use it for current desktop */
            p_verbose("WM provides _NET_WORKAREA value only for the current desktop.\n");
            for (i = 0; i < *num_desktops; i++) {
                if (i == *cur_desktop) {
                    desktop_workarea_str[i] = g_strdup_printf("%lu,%lu %lux%lu", 
                        desktop_workarea[0], desktop_workarea[1],
                        desktop_workarea[2], desktop_workarea[3]);
                }
                else {
                    desktop_workarea_str[i] = g_strdup("N/A");
                }
            }
        }
        else {
            /* seperate values for each of desktops */
            for (i = 0; i < *num_desktops; i++) {
                if (i < desktop_workarea_size / sizeof(*desktop_workarea) / 4) {
                    desktop_workarea_str[i] = g_strdup_printf("%lu,%lu %lux%lu", 
                        desktop_workarea[i*4], desktop_workarea[i*4+1],
                        desktop_workarea[i*4+2], desktop_workarea[i*4+3]);
                }
                else {
                    desktop_workarea_str[i] = g_strdup("N/A");
                }
            }
        }
    }
    else {
        for (i = 0; i < *num_desktops; i++) {
            desktop_workarea_str[i] = g_strdup("N/A");
        }
    }
 
    /* print the list */
    for (i = 0; i < *num_desktops; i++) {
        gchar *out = get_output_str(names[i], names_are_utf8);
        printf("%-2d %c DG: %-*s  VP: %-*s  WA: %-*s  %s\n", i, i == *cur_desktop ? '*' : '-',
                longest_str(desktop_geometry_str), desktop_geometry_str[i], 
                longest_str(desktop_viewport_str), desktop_viewport_str[i], 
                longest_str(desktop_workarea_str), desktop_workarea_str[i], 
                out ? out : "N/A");
        g_free(out);
    }
    
    p_verbose("Total number of desktops: %lu\n", *num_desktops);
    p_verbose("Current desktop ID (counted from zero): %lu\n", *cur_desktop);
    
    ret = EXIT_SUCCESS;
    goto cleanup;
    
cleanup:
    g_free(names);
    g_free(num_desktops);
    g_free(cur_desktop);
    g_free(desktop_geometry);
    g_strfreev(desktop_geometry_str);
    g_free(desktop_viewport);
    g_strfreev(desktop_viewport_str);
    g_free(desktop_workarea);
    g_strfreev(desktop_workarea_str);
    g_free(list);
    
    return ret;
}/*}}}*/
예제 #14
0
파일: wmctrl.c 프로젝트: amkhlv/wmjump
int window_state (Display *disp, Window win, char *arg) {/*{{{*/
    unsigned long action;
    Atom prop1 = 0;
    Atom prop2 = 0;
    char *p1, *p2;
    const char *argerr = "The -b option expects a list of comma separated parameters: \"(remove|add|toggle),<PROP1>[,<PROP2>]\"\n";

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

    if ((p1 = strchr(arg, ','))) {
        gchar *tmp_prop1, *tmp1;
        
        *p1 = '\0';

        /* action */
        if (strcmp(arg, "remove") == 0) {
            action = _NET_WM_STATE_REMOVE;
        }
        else if (strcmp(arg, "add") == 0) {
            action = _NET_WM_STATE_ADD;
        }
        else if (strcmp(arg, "toggle") == 0) {
            action = _NET_WM_STATE_TOGGLE;
        }
        else {
            fputs("Invalid action. Use either remove, add or toggle.\n", stderr);
            return EXIT_FAILURE;
        }
        p1++;

        /* the second property */
        if ((p2 = strchr(p1, ','))) {
            gchar *tmp_prop2, *tmp2;
            *p2 = '\0';
            p2++;
            if (strlen(p2) == 0) {
                fputs("Invalid zero length property.\n", stderr);
                return EXIT_FAILURE;
            }
            tmp_prop2 = g_strdup_printf("_NET_WM_STATE_%s", tmp2 = g_ascii_strup(p2, -1));
            p_verbose("State 2: %s\n", tmp_prop2); 
            prop2 = XInternAtom(disp, tmp_prop2, False);
            g_free(tmp2);
            g_free(tmp_prop2);
        }

        /* the first property */
        if (strlen(p1) == 0) {
            fputs("Invalid zero length property.\n", stderr);
            return EXIT_FAILURE;
        }
        tmp_prop1 = g_strdup_printf("_NET_WM_STATE_%s", tmp1 = g_ascii_strup(p1, -1));
        p_verbose("State 1: %s\n", tmp_prop1); 
        prop1 = XInternAtom(disp, tmp_prop1, False);
        g_free(tmp1);
        g_free(tmp_prop1);

        
        return client_msg(disp, win, "_NET_WM_STATE", 
            action, (unsigned long)prop1, (unsigned long)prop2, 0, 0);
    }
    else {
        fputs(argerr, stderr);
        return EXIT_FAILURE;
    }
}/*}}}*/