Ejemplo n.º 1
0
int window_switch(const char *windowName) { /* {{{ */
    int opt;
    int ret = EXIT_SUCCESS;
    int missing_option = 1;
    Display *disp;

    memset(&options, 0, sizeof(options)); /* just for sure */
    
    /* necessary to make g_get_charset() and g_locale_*() work */
    setlocale(LC_ALL, "");
    
    options.param_window=malloc(strlen(windowName));
    strncpy(options.param_window,windowName,strlen(windowName));

    init_charset();
    
    if (! (disp = XOpenDisplay(NULL))) {
        fputs("Cannot open display.\n", stderr);
        return EXIT_FAILURE;
    }
    if (! options.param_window) {
        fputs("No window was specified.\n", stderr);
        return EXIT_FAILURE;
    }
        ret = action_window_str(disp, 'a');
    XCloseDisplay(disp);
    return ret;
}
Ejemplo n.º 2
0
int drv_mps803_init(void)
{
    static const char *color_names[2] =
    {
        "Black", "White"
    };

    drv803_log = log_open("MPS-803");

    init_charset(charset, "mps803");

    palette = palette_create(2, color_names);

    if (palette == NULL) {
        return -1;
    }

    if (palette_load("mps803" FSDEV_EXT_SEP_STR "vpl", palette) < 0) {
        log_error(drv803_log, "Cannot load palette file `%s'.",
                  "mps803" FSDEV_EXT_SEP_STR "vpl");
        return -1;
    }

    return 0;
}
Ejemplo n.º 3
0
int close_win_by_title(gchar *title)
{
    Window *client_list;
    unsigned long client_list_size;
	int count;
    int i;
	Display *disp;

	setlocale(LC_ALL, "");
	init_charset();/*lkadd*/
	if (! (disp = XOpenDisplay(NULL)))
	{
		fputs("Cannot open display.\n", stderr);
		return 1;
	}/*打开显示*/
    if((client_list = get_client_list(disp, &client_list_size)) == NULL)
	{
        return EXIT_FAILURE; 
    } 

	count = client_list_size / sizeof(Window);
    for (i = 0; i < count; i++)
	{
        gchar *title_utf8 = get_window_title(disp, client_list[i]); /* UTF8 */
        gchar *title_out = get_output_str(title_utf8, TRUE);

		if(g_strcasecmp(title, title_out) == 0)
		{
			close_window(disp, client_list[i]);
			break;
		}
        g_free(title_utf8);
        g_free(title_out);
    }
    g_free(client_list);
	XCloseDisplay(disp);

	if(i >= count)
	{
		return EXIT_SUCCESS;
	}
	else
	{
#if MY_DEBUG_OUTPUT == 1
		g_print("cann't find the window with title:%s \n", title);
#endif
		return 1;
	}
}
Ejemplo n.º 4
0
/*
 * Return the name of the Window Manager.
 * Return NULL if it's not detected.
 *
 * NB: It must be freed by g_free()
 */
gchar *detect_window_manager()
{
    gchar *name;
    Display *disp;

    init_charset();

    if(!(disp = XOpenDisplay(NULL)))
        return NULL;

    name = wm_get_name(disp);

    XCloseDisplay(disp);

    return name;
}
Ejemplo n.º 5
0
Window *get_window_list(Display *disp, int *count)
{
    Window *client_list;
    unsigned long client_list_size;
	setlocale(LC_ALL, "");
	init_charset();/*lkadd*/
    if((client_list = get_client_list(disp, &client_list_size)) == NULL)
	{
        return NULL; 
    } 

	if(count != NULL)
	{
		*count = client_list_size / sizeof(Window);
	}
	return client_list;
}
Ejemplo n.º 6
0
int main(int argc, char **argv) {
    int ret = EXIT_SUCCESS;

    Display *disp;

    /* necessary to make g_get_charset() and g_locale_*() work */
    setlocale(LC_ALL, "");    

    init_charset();

    if(!(disp = XOpenDisplay(NULL))) {
        fputs("Cannot open display.\n", stderr);
        return EXIT_FAILURE;
    }

    ret = wm_info(disp);

    XCloseDisplay(disp);
    return ret;
}
Ejemplo n.º 7
0
Archivo: main.c Proyecto: amkhlv/wmjump
int main(int argc, char **argv)
{
 current_only = False;
 do_check_desktop = False;
 given_groupnumber = False;
 autodestroy_on_lost_focus = True;
 boldface = False;
 piped = False;
 double_clutch = True;
 add_timeout = False;
 move_window = False;
 verbose = False;

 int groupnumber = 0;
 int loc_x = 0; int loc_y = 0;
 int timeout_sec;
 

/* scanning the command line : */
 int ia; 
 for (ia = 0; ia < argc; ia++) 
   { 
   if ((strcmp(argv[ia],"-c") == 0) || (strcmp(argv[ia],"--current") == 0)) 
        { current_only=True; }
   else if ((strcmp(argv[ia],"-r") == 0) || (strcmp(argv[ia],"--reverse") == 0)) 
        { reverse_list=True; }
   else if ((strcmp(argv[ia],"-p") == 0) || (strcmp(argv[ia],"--persist") == 0)) 
        { autodestroy_on_lost_focus = False; }
   else if (strcmp(argv[ia],"--rich") == 0)   { boldface=True; }
   else if (strcmp(argv[ia],"--pipe") == 0)   { piped=True; }
   else if (strcmp(argv[ia],"--easy") == 0)   { double_clutch=False; }
   else if (sscanf(argv[ia],"--timeout=%d", &timeout_sec) == 1) { add_timeout=True; }
   else if ((strcmp(argv[ia],"-v") == 0) || (strcmp(argv[ia],"--verbose") == 0))
        { verbose = True;  }
   else if (sscanf(argv[ia],"--location=%dx%d", &loc_x, &loc_y) == 2)
        { move_window=True; }
   if (strcmp(argv[ia],"-g") == 0)
            {
             ia++; 
             if (sscanf(argv[ia],"%d",&groupnumber) == 1) 
                   {given_groupnumber = True;} else {
                             printf("\n**** parsing error of -g ***\n");
                                                     };
            }
   else if (strncmp(argv[ia],"-g",2) == 0)
            {
             if (sscanf(argv[ia],"-g%d",&groupnumber) == 1)  
                {given_groupnumber = True;}
            }
   }

 if ((given_groupnumber) && (verbose)) {
  printf("\nwmjump invoked with -g %d => assuming we are on workspace No. %d ...\n\n",
         groupnumber, groupnumber);
                        }

 lttr = g_strsplit(lttrs, "," , 0);

 wait_time_short.tv_sec=0; wait_time_short.tv_nsec=TIME_SHORT;
 wait_time_middle.tv_sec=0; wait_time_middle.tv_nsec=TIME_SHORT;
 wait_time_long.tv_sec=0; wait_time_long.tv_nsec=TIME_LONG;

 setlocale(LC_ALL, "");
 init_charset();

 home = getenv("HOME");

 /* Checking if ~/.wmjump exists, and if not creating it: */
 gchar *wmjump_dirname = g_strconcat(home,"/.wmjump/",NULL);
 if (!g_file_test(wmjump_dirname, G_FILE_TEST_EXISTS)) {
     g_print ("Creating %s directory. \n", wmjump_dirname);
     if (g_mkdir(wmjump_dirname, 0700)==-1) { 
        fputs("ERROR: Cannot create directory ~/.wmjump \n", stderr);
        return EXIT_FAILURE; }
 } 

 /* Checking the pipe: */
    if (piped) {
        remove(g_strconcat(home,"/.wmjump/",PIPEFILE,NULL));
        mknod( g_strconcat(home,"/.wmjump/",PIPEFILE,NULL), S_IFIFO|0666, 0);
    }

 /* ---------------- MAIN LOOP --------------- */
 /* The loop is needed only in piped mode, in normal mode no need to loop */
 gboolean not_enough = True;
 while (not_enough) { if (verbose) printf("wmjump is entering main loop\n"); 
  /* Pipework: */
  int pipe_descr[2];
  if (pipe(pipe_descr) != 0) {printf("wmjump: --- could not open pipe ---\n"); return EXIT_FAILURE; }
 
  if (fork()) { /* parent process */ 
     char next_command[100];
     close(pipe_descr[1]);
     if ( read(pipe_descr[0], next_command, sizeof(next_command)) == -1 ) {
                        printf("wmjump: --- could not read the pipe ---\n"); return EXIT_FAILURE; }

     Display *disp;
     if (! (disp = XOpenDisplay(NULL))) {
         fputs("Cannot open display.\n", stderr);
         return EXIT_FAILURE;
     }
 
     int child_status;
     wait(&child_status);
     do_what_user_said (disp, next_command);
 
     XCloseDisplay(disp);
     not_enough = False ;
     if (! WIFEXITED(child_status)) { printf("wmjump: error") ;}
     else { if (piped) {if (WEXITSTATUS(child_status) == 3)  {not_enough = True;} }}
     /* if ((child_status/256 == 3) && piped ) {not_enough = True;} */
  } else {  /* child process */
     close(pipe_descr[0]);
     int exit_code = 0;
 
     if (piped) {
         FILE *named_pipe;
         named_pipe = fopen(g_strconcat(home,"/.wmjump/",PIPEFILE,NULL), "r");
         gchar go_string[20];
         fgets(go_string, 20, named_pipe);
         if      (strcmp(go_string,"all\n") == 0)     { current_only=False; exit_code = 3; }
         else if (strcmp(go_string,"current\n") == 0) { current_only=True;  exit_code = 3; }
         else {  /* exiting the program */
             printf("wmjump: EXITING\n");
             char a[100];
             sprintf(a,"do_nothing");
             if ( write(pipe_descr[1], a, strlen(a)+1) == -1 ) 
                 printf("wmjump: --- could not write to pipe ---\n"); 
             exit(0);
         }
 
         fclose(named_pipe);
     }
 
     if (current_only) { do_check_desktop=True; }
 
     Display *disp;
     if (! (disp = XOpenDisplay(NULL))) {
         fputs("wmjump: Cannot open display.\n", stderr);
         return EXIT_FAILURE;
     }
 
     Window *client_list_direct_order;
     unsigned long client_list_size;
     if ((client_list_direct_order = get_client_list(disp, &client_list_size)) == NULL) {
         printf("wmjump: Cannot get client list");
         return EXIT_FAILURE; 
     }
     
     int szofw=sizeof(Window);
     Window *client_list = g_malloc(client_list_size*szofw);
     /* reversing the list if required */
     unsigned int j;
     for (j=0; j<client_list_size/szofw; j++)
         { 
           if (reverse_list) 
                { client_list[j] = client_list_direct_order[client_list_size/szofw - j - 1]; }
           else { client_list[j] = client_list_direct_order[j]; }
         }
 
     unsigned int number_of_buttons;
     int* window_number = malloc(client_list_size / sizeof(Window) * sizeof(int));
     gchar** title_of_button; 
     gchar** name_of_style;
     title_of_button = g_malloc0( ( client_list_size/sizeof(Window) + 1) * sizeof(gchar*) );
     name_of_style   = g_malloc0( ( client_list_size/sizeof(Window) + 1) * sizeof(gchar*) );
     Window win_we_leave;
     gboolean win_we_leave_is_blacklisted ;
 
     get_list_from_wm(   disp, 
                         client_list, 
                         client_list_size, 
                         &number_of_buttons, 
                         window_number,
                         title_of_button,
                         name_of_style,
                         groupnumber,
                         &win_we_leave,
                         &win_we_leave_is_blacklisted) ;
 
 
     XSync(disp,FALSE);
     XCloseDisplay(disp);
     
     our_user_interface(pipe_descr,
                        client_list,
                        client_list_size,
                        number_of_buttons, 
                        title_of_button, 
                        name_of_style,
                        window_number,
                        win_we_leave,
                        win_we_leave_is_blacklisted,
                        loc_x, loc_y, timeout_sec);
 
     g_free(client_list); client_list = NULL ;
     g_free(client_list_direct_order); client_list_direct_order = NULL ;
     free(window_number); window_number = NULL ;
     g_strfreev(title_of_button);  title_of_button = NULL ;
     g_strfreev(name_of_style);  name_of_style = NULL ;
     exit(exit_code);
     }
 }  if (verbose) { printf("wmjump exiting main loop\n"); 
                   printf("=======================================================\n\n"); }
 g_strfreev(lttr); lttr = NULL ;
 exit(0);
}
Ejemplo n.º 8
0
Window* get_window_by_title(Display *disp, gchar *title, int *num)
{
    Window *client_list;
    unsigned long client_list_size;
	/*窗口总数*/
	int countAll = 0;
	/*具有相同标题title的窗口数目*/
	int count = 0;
	/*记录具有相同标题的窗口在client_list中的下标*/
	int *record;
	/*具有title标题的窗口*/
	Window *windows;
	int i = 0;


	setlocale(LC_ALL, "");
	init_charset();
    if((client_list = get_client_list(disp, &client_list_size)) == NULL)
	{
        return NULL; 
    } 

	countAll = client_list_size / sizeof(Window);
	record = (int*)malloc(sizeof(int) * countAll);

	for(i = 0; i < countAll; ++i)
	{
		record[i] = -1;
	}


	for(i = 0; i < countAll; ++i)
	{
		gchar *title_utf8 = get_window_title(disp, client_list[i]); /* UTF8 */
#if MY_DEBUG_OUTPUT == 1
		g_print("after get_window_title**\n");
#endif
		gchar *title_out = get_output_str(title_utf8, TRUE);
#if MY_DEBUG_OUTPUT == 1
		g_print(title_out);
		g_print("*******title_out is ok??\n");
#endif
		if(g_strcasecmp(title, title_out) == 0)
		{
			record[i] = 1;
			++count;
		}
		g_free(title_utf8);
		g_free(title_out);
	}

	/*存放相同标题的窗口*/
	windows = (Window*)malloc(sizeof(Window)*count);
	for(i = 0; i < countAll; ++i)
	{
		if(record[i] > 0)
		{
			windows[i] = client_list[i];
		}
	}
	*num = count;

	free(record);
	return windows;
}