Ejemplo n.º 1
0
Archivo: kbd.c Proyecto: Efreak/elinks
void
dispatch_special(unsigned char *text)
{
	switch (text[0]) {
		case TERM_FN_TITLE:
			if (ditrm) {
				if (ditrm->remote)
					break;

				/* If ditrm->touched_title is 0, then
				 * ditrm->orig_title should be NULL,
				 * but check it to prevent any leak.  */
				if (!ditrm->orig_title && !ditrm->touched_title)
					ditrm->orig_title = get_window_title(
						ditrm->title_codepage);
				ditrm->touched_title = 1;
			}
			/* TODO: Is it really possible to get here with
			 * ditrm == NULL, and which charset would then
			 * be most appropriate?  */
			set_window_title(text + 1,
					 ditrm ? ditrm->title_codepage
					 : get_cp_index("US-ASCII"));
			break;
		case TERM_FN_RESIZE:
			if (ditrm && ditrm->remote)
				break;

			resize_terminal_from_str(text + 1);
			break;
		case TERM_FN_TITLE_CODEPAGE:
			if (ditrm) {
				int cp = get_cp_index(text + 1);

				/* If the master sends the name of an
				 * unrecognized charset, assume only
				 * that it's ASCII compatible.  */
				if (cp == -1)
					cp = get_cp_index("US-ASCII");
				ditrm->title_codepage = cp;
			}
			break;
	}
}
Ejemplo n.º 2
0
int main(int, char**)
{
	HWND previous_foreground_window = nullptr;
	for (;;)
	{
		HWND foreground_window = GetForegroundWindow();
		if (foreground_window != nullptr && foreground_window != previous_foreground_window)
		{
			//Foreground window changed.
			std::wstring filename(get_process_filename(foreground_window));
			std::wstring window_title(get_window_title(foreground_window));
			std::wstring timestamp(get_current_timestamp());
			// Format: [HH:MM:SS] name.exe | Window Title
			wprintf(L"%s %s | %s\n", timestamp.c_str(), filename.c_str(), window_title.c_str());
			previous_foreground_window = foreground_window;
		}

		Sleep(100);
	}
}
Ejemplo n.º 3
0
static void window_title_changed_cb (GtkWidget *widget, gpointer data)
{
    DEBUG_FUNCTION ("window_title_changed_cb");
    DEBUG_ASSERT (widget != NULL);
    DEBUG_ASSERT (data != NULL);

    tilda_term *tt = TILDA_TERM(data);
    gchar *title = get_window_title (widget);
    GtkWidget *label;

    label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (tt->tw->notebook), tt->hbox);
    /* We need to check if the widget that received the title change is the currently
     * active tab. If not we should not update the window title. */
    gint page = gtk_notebook_get_current_page (GTK_NOTEBOOK (tt->tw->notebook));
    GtkWidget *active_page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (tt->tw->notebook), page);
    gboolean active = widget == active_page;

    guint length = (guint) config_getint ("title_max_length");

    if(config_getbool("title_max_length_flag") && strlen(title) > length) {
        gchar *titleOffset = title + strlen(title) - length;
        gchar *shortTitle = g_strdup_printf ("...%s", titleOffset);
        gtk_label_set_text (GTK_LABEL(label), shortTitle);
        if (active) {
            gtk_window_set_title (GTK_WINDOW (tt->tw->window), shortTitle);
        }
        g_free(shortTitle);
    } else {
        gtk_label_set_text (GTK_LABEL(label), title);
        if (active) {
            gtk_window_set_title (GTK_WINDOW (tt->tw->window), title);
        }
    }

    g_free (title);
}
Ejemplo n.º 4
0
static si_t _server_lib_handle_request(addr_t body, si_t detail_type, union respond* respond_ptr, addr_t app_addr)
{
    /** 存储调用实际操作函数结果的变量 **/
    si_t func_ret = 0;
    /** 存储_server_lib_handle_request()返回值的变量 **/
    si_t handler_ret = SELECTER_RETURN_TYPE_CONTINUE;
    switch(detail_type)
    {
    case REQUEST_TYPE_REGISTER_APPLICATION:
    {
        si_t video_access_mode = 0, application_type = 0;
        char* app_name = NULL;
        request_get_register_application(body, &video_access_mode, &application_type, &app_name, NULL);
        func_ret = register_application_handler(app_addr, video_access_mode, application_type, app_name);
        respond_set_normal(respond_ptr, RESPOND_TYPE_REGISTER_APPLICATION, func_ret);
    }
    break;
    case REQUEST_TYPE_CANCEL_APPLICATION:
        respond_set_normal(respond_ptr, RESPOND_TYPE_CANCEL_APPLICATION, 0);
        handler_ret = SELECTER_RETURN_TYPE_REMOVE_HANDLER;
        break;
    /**
     * 处理初始化/清理图形设备的请求:
     * 首先从请求包中获取必要参数,
     * 接着调用graph模块的函数对图形设备初始化/清理,
     * 接着将获得的参数和应用程序指针传递给上层的回调函数进行处理
     * 最后将上层回调函数的返回值作为回应包的返回值
     **/
    case REQUEST_TYPE_GRAPHICS_DEVICE_INIT:
    {
        si_t gd = request_call_by_graphics_device_init(body, engine_graphics_device_init);
        func_ret = graphics_device_init_handler(app_addr, gd);
        respond_set_normal(respond_ptr, RESPOND_TYPE_GRAPHICS_DEVICE_INIT, gd);
    }
    break;
    case REQUEST_TYPE_GRAPHICS_DEVICE_EXIT:
    {
        si_t gd = 0;
        request_get_graphics_device_exit(body, &gd);
        func_ret = request_call_by_graphics_device_exit(body, engine_graphics_device_exit);
        func_ret = graphics_device_exit_handler(app_addr, gd);
        respond_set_normal(respond_ptr, RESPOND_TYPE_GRAPHICS_DEVICE_EXIT, func_ret);
    }
    break;
    /**
     * 接到window_manager_quit命令 若成功执行则返回退出循环的
     **/
    case REQUEST_TYPE_WINDOW_MANAGER_QUIT:
        func_ret = window_manager_exit_handler(app_addr);
        respond_set_normal(respond_ptr, RESPOND_TYPE_WINDOW_MANAGER_QUIT, func_ret);
        if(0 == func_ret)
        {
            handler_ret = SELECTER_RETURN_TYPE_END;
        }
        break;
    case REQUEST_TYPE_DESKTOP_DIRTY:
        func_ret = desktop_dirty_handler(app_addr);
        respond_set_normal(respond_ptr, RESPOND_TYPE_DESKTOP_DIRTY, func_ret);
        break;
    case REQUEST_TYPE_UPDATE:
    {
        si_t gd = 0;
        request_get_update(body, &gd);
        func_ret = update_handler(app_addr, gd);
        respond_set_normal(respond_ptr, RESPOND_TYPE_UPDATE, func_ret);
    }
    break;
    case REQUEST_TYPE_ACTIVATE_WINDOW:
    {
        si_t window_descripter = 0;
        request_get_activate_window(body, &window_descripter);
        func_ret = activate_window_handler(app_addr, window_descripter);
        respond_set_normal(respond_ptr, RESPOND_TYPE_ACTIVATE_WINDOW, func_ret);
    }
    break;
    case REQUEST_TYPE_REGISTER_WINDOW:
    {
        si_t window_descripter = 0, x_axis = 0, y_axis = 0, x_size = 0, y_size = 0, maxable = 0, minable = 0, model = 0;
        char* title = NULL;
        request_get_register_window(body, &window_descripter, &title, NULL, &x_axis, &y_axis, &x_size, &y_size, &minable, &maxable, &model);
        func_ret = register_window_handler(app_addr, window_descripter, title, x_axis, y_axis, x_size, y_size, minable, maxable, model);
        respond_set_normal(respond_ptr, RESPOND_TYPE_REGISTER_WINDOW, func_ret);
    }
    break;
    case REQUEST_TYPE_CANCEL_WINDOW:
    {
        si_t window_descripter = 0;
        request_get_cancel_window(body, &window_descripter);
        func_ret = cancel_window_handler(app_addr, window_descripter);
        respond_set_normal(respond_ptr, RESPOND_TYPE_CANCEL_WINDOW, func_ret);
    }
    break;
    case REQUEST_TYPE_MOVE_WINDOW:
    {
        si_t window_descripter = 0, x_axis = 0, y_axis = 0;
        request_get_move_window(body, &window_descripter, &x_axis, &y_axis);
        func_ret = move_window_handler(app_addr, window_descripter, x_axis, y_axis);
        respond_set_normal(respond_ptr, RESPOND_TYPE_MOVE_WINDOW, func_ret);
    }
    break;
    case REQUEST_TYPE_RESIZE_WINDOW:
    {
        si_t window_descripter = 0, x_axis = 0, y_axis = 0, x_size = 0, y_size = 0;
        request_get_resize_window(body, &window_descripter, &x_axis, &y_axis, &x_size, &y_size);
        func_ret = resize_window_handler(app_addr, window_descripter, x_axis, y_axis, x_size, y_size);
        respond_set_normal(respond_ptr, RESPOND_TYPE_RESIZE_WINDOW, func_ret);
    }
    break;
    case REQUEST_TYPE_MINIMIZE_WINDOW:
    {
        si_t window_descripter = 0;
        request_get_minimize_window(body, &window_descripter);
        func_ret = minimize_window_handler(app_addr, window_descripter);
        respond_set_normal(respond_ptr, RESPOND_TYPE_MINIMIZE_WINDOW, func_ret);
    }
    break;
    case REQUEST_TYPE_MAXIMIZE_WINDOW:
    {
        si_t window_descripter = 0;
        struct rectangle area;
        request_get_maximize_window(body, &window_descripter);
        func_ret = maximize_window_handler(app_addr, window_descripter, &area);
        respond_set_rectangle(respond_ptr, RESPOND_TYPE_MAXIMIZE_WINDOW, &area);
    }
    break;
    case REQUEST_TYPE_RESTORE_WINDOW:
    {
        si_t window_descripter = 0;
        struct rectangle area;
        request_get_restore_window(body, &window_descripter, &area.x, &area.y, &area.width, &area.height);
        func_ret = restore_window_handler(app_addr, window_descripter, &area);
        respond_set_normal(respond_ptr, RESPOND_TYPE_RESTORE_WINDOW, func_ret);
    }
    break;
    case REQUEST_TYPE_GET_WINDOW_TITLE:
    {
        si_t window_descripter = 0;
        char* title = NULL;
        request_get_window_title(body, &window_descripter);
        get_window_title(app_addr, window_descripter, &title);
        respond_set_va(respond_ptr, RESPOND_TYPE_GET_WINDOW_TITLE, title, strlen(title) + 1);
    }
    break;
    }
    return handler_ret;
}
static void make_window(const char* title) {
    RECT WindowRect = {0,0,0,0};
    int width, height;
    DWORD dwExStyle;
    DWORD dwStyle;

    if (fullscreen) {
        HDC screenDC=GetDC(NULL);
        WindowRect.left = WindowRect.top = 0;
        WindowRect.right=GetDeviceCaps(screenDC, HORZRES);
        WindowRect.bottom=GetDeviceCaps(screenDC, VERTRES);
        ReleaseDC(NULL, screenDC);
        dwExStyle=WS_EX_TOPMOST;
        dwStyle=WS_POPUP;
        while(ShowCursor(false) >= 0);
    } else {
        // Version 5 screensaver logic kills all MODE_WINDOW graphics before starting one
        // in fullscreen mode, then restarts the ones it killed when screensaver stops.
        // To be compatible with V5, we remember and restore the MODE_WINDOW dimensions.
        FILE *f = boinc_fopen("gfx_info", "r");
        if (f) {
            // ToDo: change this to XML parsing
            fscanf(f, "%d %d %d %d\n", &rect.left, &rect.top, &rect.right, &rect.bottom);
            fclose(f);
        }
        WindowRect = rect;
        dwExStyle=WS_EX_APPWINDOW|WS_EX_WINDOWEDGE;
        dwStyle=WS_OVERLAPPEDWINDOW;
        while(ShowCursor(true) < 0);
    }

    char window_title[256];
    if (title) {
        strcpy(window_title, title);
    } else {
        APP_INIT_DATA aid;
        boinc_get_init_data(aid);
        if (!strlen(aid.app_name)) strcpy(aid.app_name, "BOINC Application");
        get_window_title(window_title, 256);
    }

    //fprintf(stderr, "Setting window title to '%s'.\n", window_title);

    hWnd = CreateWindowEx(dwExStyle, BOINC_WINDOW_CLASS_NAME, window_title,
        dwStyle|WS_CLIPSIBLINGS|WS_CLIPCHILDREN, WindowRect.left, WindowRect.top,
        WindowRect.right-WindowRect.left,WindowRect.bottom-WindowRect.top,
        NULL, NULL, hInstance, NULL
    );

    if (!SetForegroundWindow(hWnd)) {
        fprintf(stderr,
            "%s ERROR: Unable to set foreground window (0x%x).\n",
            boinc_msg_prefix(), GetLastError()
        );
    }

    if (!GetCursorPos(&mousePos)) {
        fprintf(stderr,
            "%s ERROR: Unable to get mouse cursor position (0x%x).\n",
            boinc_msg_prefix(), GetLastError()
        );
    }

    hDC = GetDC(hWnd);
    if (!hDC) {
        fprintf(stderr,
            "%s ERROR: Couldn't get a device context for the window (0x%x).\n",
            boinc_msg_prefix(), GetLastError()
        );
    }
    SetupPixelFormat(hDC);

    hRC = wglCreateContext(hDC);
    if (!hRC) {
        fprintf(stderr,
            "%s ERROR: Unable to create OpenGL context (0x%x).\n",
            boinc_msg_prefix(), GetLastError()
        );
        ReleaseDC(hWnd, hDC);
        return;
    }

    if(!wglMakeCurrent(hDC, hRC)) {
        fprintf(stderr,
            "%s ERROR: Unable to make OpenGL context current (0x%x).\n",
            boinc_msg_prefix(), GetLastError()
        );
        ReleaseDC(hWnd, hDC);
        wglDeleteContext(hRC);
        return;
    }

    // use client area for resize when not fullscreen
    if (current_graphics_mode != MODE_FULLSCREEN) {
        GetClientRect(hWnd, &WindowRect);
	}

    width = WindowRect.right-WindowRect.left;
    height = WindowRect.bottom-WindowRect.top;

    ShowWindow(hWnd, SW_SHOW);
    SetFocus(hWnd);

    app_graphics_init();
    app_graphics_resize(width, height);

    window_ready=true;
}
Ejemplo n.º 6
0
Archivo: main.c Proyecto: 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 ;
}
Ejemplo n.º 7
0
int list_windows (Display *disp) {/*{{{*/
    Window *client_list;
    unsigned long client_list_size;
    unsigned int i;
    int max_client_machine_len = 0;
    
    if ((client_list = get_client_list(disp, &client_list_size)) == NULL) {
        return EXIT_FAILURE; 
    }
    
    /* find the longest client_machine name */
    for (i = 0; i < client_list_size / sizeof(Window); i++) {
        gchar *client_machine;
        if ((client_machine = get_property(disp, client_list[i],
                XA_STRING, "WM_CLIENT_MACHINE", NULL))) {
            max_client_machine_len = strlen(client_machine);    
        }
        g_free(client_machine);
    }
    
    /* print the list */
    for (i = 0; i < client_list_size / sizeof(Window); i++) {
        gchar *title_utf8 = get_window_title(disp, client_list[i]); /* UTF8 */
        gchar *title_out = get_output_str(title_utf8, TRUE);
        gchar *client_machine;
        gchar *class_out = get_window_class(disp, client_list[i]); /* UTF8 */
        unsigned long *pid;
        unsigned long *desktop;
        int x, y, junkx, junky;
        unsigned int wwidth, wheight, bw, depth;
        Window junkroot;

        /* desktop ID */
        if ((desktop = (unsigned long *)get_property(disp, client_list[i],
                XA_CARDINAL, "_NET_WM_DESKTOP", NULL)) == NULL) {
            desktop = (unsigned long *)get_property(disp, client_list[i],
                    XA_CARDINAL, "_WIN_WORKSPACE", NULL);
        }

        /* client machine */
        client_machine = get_property(disp, client_list[i],
                XA_STRING, "WM_CLIENT_MACHINE", NULL);
       
        /* pid */
        pid = (unsigned long *)get_property(disp, client_list[i],
                XA_CARDINAL, "_NET_WM_PID", NULL);

	    /* geometry */
        XGetGeometry (disp, client_list[i], &junkroot, &junkx, &junky,
                          &wwidth, &wheight, &bw, &depth);
        XTranslateCoordinates (disp, client_list[i], junkroot, junkx, junky,
                               &x, &y, &junkroot);
      
        /* special desktop ID -1 means "all desktops", so we 
           have to convert the desktop value to signed long */
        printf("0x%.8lx %2ld", client_list[i], 
                desktop ? (signed long)*desktop : 0);
        if (options.show_pid) {
           printf(" %-6lu", pid ? *pid : 0);
        }
        if (options.show_geometry) {
           printf(" %-4d %-4d %-4d %-4d", x, y, wwidth, wheight);
        }
		if (options.show_class) {
		   printf(" %-20s ", class_out ? class_out : "N/A");
		}

        printf(" %*s %s\n",
              max_client_machine_len,
              client_machine ? client_machine : "N/A",
              title_out ? title_out : "N/A"
		);
        g_free(title_utf8);
        g_free(title_out);
        g_free(desktop);
        g_free(client_machine);
        g_free(class_out);
        g_free(pid);
    }
    g_free(client_list);
   
    return EXIT_SUCCESS;
}/*}}}*/
Ejemplo n.º 8
0
int action_window_str (Display *disp, char mode) {/*{{{*/
    Window activate = 0;
    Window *client_list;
    unsigned long client_list_size;
    unsigned int i;
    
    if (strcmp(SELECT_WINDOW_MAGIC, options.param_window) == 0) {
        activate = Select_Window(disp);
        if (activate) {
            return action_window(disp, activate, mode);
        }
        else {
            return EXIT_FAILURE;
        }
    }
    if (strcmp(ACTIVE_WINDOW_MAGIC, options.param_window) == 0) {
        activate = get_active_window(disp);
        if (activate)
        {
            return action_window(disp, activate, mode);
        }
        else
        {
            return EXIT_FAILURE;
        }
    }
    else {
        if ((client_list = get_client_list(disp, &client_list_size)) == NULL) {
            return EXIT_FAILURE; 
        }
        
        for (i = 0; i < client_list_size / sizeof(Window); i++) {
 			gchar *match_utf8;
 			if (options.show_class) {
 	            match_utf8 = get_window_class(disp, client_list[i]); /* UTF8 */
 			}
 			else {
 				match_utf8 = get_window_title(disp, client_list[i]); /* UTF8 */
 			}
            if (match_utf8) {
                gchar *match;
                gchar *match_cf;
                gchar *match_utf8_cf = NULL;
                if (envir_utf8) {
                    match = g_strdup(options.param_window);
                    match_cf = g_utf8_casefold(options.param_window, -1);
                }
                else {
                    if (! (match = g_locale_to_utf8(options.param_window, -1, NULL, NULL, NULL))) {
                        match = g_strdup(options.param_window);
                    }
                    match_cf = g_utf8_casefold(match, -1);
                }
                
                if (!match || !match_cf) {
                    continue;
                }

                match_utf8_cf = g_utf8_casefold(match_utf8, -1);

                if ((options.full_window_title_match && strcmp(match_utf8, match) == 0) ||
                        (!options.full_window_title_match && strstr(match_utf8_cf, match_cf))) {
                    activate = client_list[i];
                    g_free(match);
                    g_free(match_cf);
                    g_free(match_utf8);
                    g_free(match_utf8_cf);
                    break;
                }
                g_free(match);
                g_free(match_cf);
                g_free(match_utf8);
                g_free(match_utf8_cf);
            }
        }
        g_free(client_list);

        if (activate) {
            return action_window(disp, activate, mode);
        }
        else {
            return EXIT_FAILURE;
        }
    }
}/*}}}*/
MpInterface::PlayerStatus KviSpotifyInterface::status() {
	if (get_window_title() == QString(""))
		return MpInterface::Stopped;
	else
		return MpInterface::Playing;
}
QString KviSpotifyInterface::nowPlaying()
{
	return get_window_title().replace(QString("\u2013"), QString("-"));
}
Ejemplo n.º 11
0
void print_win_info(Display *disp, Window *win)
{
	gchar *title_utf8 = get_window_title(disp, *win); /* UTF8 */
	gchar *title_out = get_output_str(title_utf8, TRUE);

	gchar *client_machine;
	gchar *class_out = get_window_class(disp, *win); /* UTF8 */

	unsigned long *pid;
	unsigned long *desktop;
	int x, y, junkx, junky;
	unsigned int wwidth, wheight, bw, depth;
	Window junkroot;

	/* desktop ID */
	if ((desktop = (unsigned long *)get_property(disp, *win,
					XA_CARDINAL, "_NET_WM_DESKTOP", NULL)) == NULL) {
		desktop = (unsigned long *)get_property(disp, *win,
				XA_CARDINAL, "_WIN_WORKSPACE", NULL);
	}

	/* client machine */
	client_machine = get_property(disp, *win,
			XA_STRING, "WM_CLIENT_MACHINE", NULL);

	/* pid */
	pid = (unsigned long *)get_property(disp, *win,
			XA_CARDINAL, "_NET_WM_PID", NULL);

	/* geometry */
	/*        XGetGeometry (disp, client_list[i], &junkroot, &junkx, &junky,
			  &wwidth, &wheight, &bw, &depth);
			  XTranslateCoordinates (disp, client_list[i], junkroot, junkx, junky,
			  &x, &y, &junkroot);*/

	/* special desktop ID -1 means "all desktops", so we 
	   have to convert the desktop value to signed long */
	printf("------\n");
	printf("WinID:");
	printf("0x%.8lx\n", *win); 
	printf("DesktopID:");
	printf("%2ld\n",
			desktop ? (signed long)*desktop : 0);

	/*show pid of the window*/
	printf("PID:");
	printf(" %-6lu\n", pid ? *pid : 0);
	/*        if (options.show_geometry) {
			  printf(" %-4d %-4d %-4d %-4d", x, y, wwidth, wheight);
			  }*/
	/*show class of the window*/
	printf("WinClass:");
	printf(" %-20s\n", class_out ? class_out : "N/A");

	printf("client_machine:");
	printf("%s\n",
			client_machine ? client_machine : "N/A"
		  );
	printf("WinTitle:");
	printf(" %s\n",
			title_out ? title_out : "N/A");
	printf("------\n");
	g_free(title_utf8);
	g_free(title_out);
	g_free(desktop);
	g_free(client_machine);
	g_free(class_out);
	g_free(pid);
}
Ejemplo n.º 12
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;
}
Ejemplo n.º 13
0
static void make_new_window(int mode) {
    if ( (mode != MODE_WINDOW) &&  (mode != MODE_FULLSCREEN) ) {
        // nothing to be done here
        return;
    }

    if (glut_is_initialized && glut_is_freeglut) {
        if (!FREEGLUT_IS_INITIALIZED) {
            glut_is_initialized = false;
            fg_window_is_fullscreen = false;
	        fg_window_state = 0;
        }
    }
    if (!glut_is_initialized)  {
        boinc_glut_init();
    }

    if (debug) fprintf(stderr, "make_new_window(): now calling glutCreateWindow(%s)...\n", aid.app_name);
    char window_title[256];
    get_window_title(aid, window_title, 256);

    // just show the window if its hidden
    // if it used to be fullscreen (before
    // it was hidden, reset size and position
    // to defaults
    //
    bool have_window = false;
    if (glut_is_freeglut && GLUT_HAVE_WINDOW) {
          have_window = true;
          glutShowWindow();
          if (fg_window_is_fullscreen) {
             glutPositionWindow(xpos, ypos);
             glutReshapeWindow(600, 400);
             fg_window_is_fullscreen = false;
          }
	  fg_window_state = MODE_WINDOW;
    }
    
#ifdef __APPLE__
    if (win)
        have_window = true;
#endif

    if (!have_window) {
        win = glutCreateWindow(window_title); 
        if (debug) fprintf(stderr, "glutCreateWindow() succeeded. win = %d\n", win);

        glutReshapeFunc(app_graphics_resize);
        glutKeyboardFunc(keyboardD);
        glutKeyboardUpFunc(keyboardU);
        glutMouseFunc(mouse_click);
        glutMotionFunc(mouse_click_move);
        glutDisplayFunc(maybe_render); 
        glEnable(GL_DEPTH_TEST);
  
        app_graphics_init();
    }
  
#ifdef __APPLE__
    glutWMCloseFunc(CloseWindow);   // Enable the window's close box
    BringAppToFront();
    // Show window only after a successful call to throttled_app_render(); 
    // this avoids momentary display of old image when screensaver restarts 
    // which made image appear to "jump."
    need_show = true;
#endif

    if (mode == MODE_FULLSCREEN)  {
        glutFullScreen();
    }

    return;
}
Ejemplo n.º 14
0
static void make_new_window() {
    RECT WindowRect = {0,0,0,0};
    int width, height;
    DWORD dwExStyle;
    DWORD dwStyle;

    if (current_graphics_mode == MODE_FULLSCREEN) {
        HDC screenDC=GetDC(NULL);
        WindowRect.left = WindowRect.top = 0;
        WindowRect.right=GetDeviceCaps(screenDC, HORZRES);
        WindowRect.bottom=GetDeviceCaps(screenDC, VERTRES);
        ReleaseDC(NULL, screenDC);
        dwExStyle=WS_EX_TOPMOST;
        dwStyle=WS_POPUP;
        while(ShowCursor(false) >= 0);
    } else {
        WindowRect = rect;
        dwExStyle=WS_EX_APPWINDOW|WS_EX_WINDOWEDGE;
        dwStyle=WS_OVERLAPPEDWINDOW;
        while(ShowCursor(true) < 0);
    }

    APP_INIT_DATA aid;
    boinc_get_init_data(aid);
    if (!strlen(aid.app_name)) {
        strlcpy(aid.app_name, "BOINC Application", sizeof(aid.app_name));
    }
    char window_title[256];
    get_window_title(aid, window_title, 256);
    hWnd = CreateWindowEx(dwExStyle, BOINC_WINDOW_CLASS_NAME, window_title,
        dwStyle|WS_CLIPSIBLINGS|WS_CLIPCHILDREN, WindowRect.left, WindowRect.top,
        WindowRect.right-WindowRect.left,WindowRect.bottom-WindowRect.top,
        NULL, NULL, hInstance, NULL
    );

    SetForegroundWindow(hWnd);

    GetCursorPos(&mousePos);

    hDC = GetDC(hWnd);
    myhDC=hDC;
    SetupPixelFormat(myhDC);

    hRC = wglCreateContext(hDC);
    if (hRC == 0) {
        ReleaseDC(hWnd, hDC);
        return;
    }

    if(!wglMakeCurrent(hDC, hRC)) {
        ReleaseDC(hWnd, hDC);
        wglDeleteContext(hRC);
        return;
    }

    // use client area for resize when not fullscreen
    if (current_graphics_mode != MODE_FULLSCREEN) {
        GetClientRect(hWnd, &WindowRect);
	}

    width = WindowRect.right-WindowRect.left;
    height = WindowRect.bottom-WindowRect.top;

    ShowWindow(hWnd, SW_SHOW);
    SetFocus(hWnd);

    app_graphics_init();
    app_graphics_resize(width, height);     
    window_ready=true;
}