static void on_name_changed (WnckWindow *window, TaskTitle *title) { g_return_if_fail (TASK_IS_TITLE (title)); g_return_if_fail (WNCK_IS_WINDOW (window)); gtk_label_set_text (GTK_LABEL (title->priv->label), wnck_window_get_name (window)); gtk_widget_set_tooltip_text (GTK_WIDGET (title), wnck_window_get_name (window)); gtk_widget_queue_draw (GTK_WIDGET (title)); }
bool Trash::isTrashWindow(WnckWindow* window) const { QString windowName = QString(wnck_window_get_name(window)); int found = QString::compare(u2dTr("Trash", "nautilus"), windowName, Qt::CaseSensitive); return found == 0; }
const gchar *wibuti_watcher_get_title(WibutiWatcher *self) { if (WNCK_IS_WINDOW(self->tracked)) { return wnck_window_get_name(self->tracked); } else { return "Desktop"; } }
static void set_active_window (WorkspaceButton* self, WnckWindow * window) { if (PRIV (self)->active == window) { return; } if (PRIV (self)->active) { PRIV (self)->active = NULL; } if (window) { PRIV (self)->active = window; gtk_image_set_from_pixbuf (GTK_IMAGE (PRIV (self)->image), wnck_window_get_mini_icon (PRIV (self)->active)); gtk_widget_show (PRIV (self)->image); gtk_label_set_text (GTK_LABEL (PRIV (self)->label), wnck_window_get_name (PRIV (self)->active)); // FIXME: connect to window state changes } else { gtk_widget_hide (PRIV (self)->image); gtk_image_set_from_pixbuf (GTK_IMAGE (PRIV (self)->image), NULL); gtk_label_set_text (GTK_LABEL (PRIV (self)->label), wnck_workspace_get_name (PRIV (self)->workspace)); } }
static void window_opened_callback (WnckScreen* , WnckWindow* window, gpointer ) { g_print ("Window '%s' opened (pid = %d session_id = %s)\n", wnck_window_get_name (window), wnck_window_get_pid (window), wnck_window_get_session_id (window) ? wnck_window_get_session_id (window) : "none"); g_signal_connect (G_OBJECT (window), "name_changed", G_CALLBACK (window_name_changed_callback), NULL); g_signal_connect (G_OBJECT (window), "state_changed", G_CALLBACK (window_state_changed_callback), NULL); g_signal_connect (G_OBJECT (window), "workspace_changed", G_CALLBACK (window_workspace_changed_callback), NULL); g_signal_connect (G_OBJECT (window), "icon_changed", G_CALLBACK (window_icon_changed_callback), NULL); g_signal_connect (G_OBJECT (window), "geometry_changed", G_CALLBACK (window_geometry_changed_callback), NULL); }
/* * max_window_name_width * * Returns: gint * Description: Calculate the width of the decoration required to display * the window name using pango (with 6px padding) * Returns zero if window has no name. */ gint max_window_name_width (WnckWindow *win) { decor_t *d = g_object_get_data (G_OBJECT (win), "decor"); const gchar *name; gint w; /* Ensure that a layout is created */ if (!d->layout) { d->layout = pango_layout_new (d->frame->pango_context); if (!d->layout) return 0; pango_layout_set_wrap (d->layout, PANGO_WRAP_CHAR); } /* Return zero if window has no name */ name = wnck_window_get_name (win); if (!name) return 0; /* Reset the width, set hte text and get the size required */ pango_layout_set_auto_dir (d->layout, FALSE); pango_layout_set_width (d->layout, -1); pango_layout_set_text (d->layout, name, strlen (name)); pango_layout_get_pixel_size (d->layout, &w, NULL); if (d->name) pango_layout_set_text (d->layout, d->name, strlen (d->name)); return w + 6; }
int main(int argc, char **argv) { WnckScreen *screen; WnckWindow *active_window; GList *window_l; gdk_init(&argc, &argv); screen = wnck_screen_get_default(); sleep(5); wnck_screen_force_update(screen); active_window = wnck_screen_get_active_window(screen); for (window_l = wnck_screen_get_windows(screen); window_l != NULL; window_l = window_l->next) { WnckWindow *window = WNCK_WINDOW(window_l->data); if (strcmp(wnck_window_get_name(window), "Terminal") == 0) { wnck_window_activate(window, (guint32)time(NULL)); break; } // g_print("Name: '%s', PID: %d(%lu)%s\n", wnck_window_get_name(window), // wnck_window_get_pid(window), wnck_window_get_xid(window), // window == active_window ? " (active)" : ""); } return 0; }
static gboolean is_menubar(WnckWindow* window) { gboolean ret = FALSE; if (wnck_window_get_window_type(window) != WNCK_WINDOW_DOCK) ret = FALSE; else if (strcmp(wnck_window_get_name(window), "GTK MENUBAR") == 0) ret = TRUE; else { Atom type; int format; gulong nitems; gulong bytes_after; Atom *data; if (XGetWindowProperty(gdk_display, wnck_window_get_xid(window), XInternAtom(gdk_display, "_NET_WM_WINDOW_TYPE", FALSE), 0, G_MAXLONG, False, XA_ATOM, &type, &format, &nitems, &bytes_after, (void*) &data) == Success && data != NULL) { if (data[0] == XInternAtom(gdk_display, "_KDE_NET_WM_WINDOW_TYPE_TOPMENU", FALSE)) ret = TRUE; XFree (data); } } return ret; }
static void update_name (WnckApplication *app) { g_assert (app->priv->name_from_leader || app->priv->name == NULL); if (app->priv->name == NULL) { /* if only one window, get name from there. If more than one and * they all have the same res_class, use that. Else we want to * use the fallback name, since using the title of one of the * windows would look wrong. */ if (app->priv->windows && app->priv->windows->next == NULL) { app->priv->name = g_strdup (wnck_window_get_name (app->priv->windows->data)); app->priv->name_window = app->priv->windows->data; emit_name_changed (app); } else if (app->priv->windows) { /* more than one */ app->priv->name = _wnck_get_res_class_utf8 (wnck_window_get_xid (app->priv->windows->data)); if (app->priv->name) { app->priv->name_window = app->priv->windows->data; emit_name_changed (app); } } } }
static void on_window_opened (WnckScreen *screen, WnckWindow *window, gpointer data) { /* Note: when this event is emitted while screen is initialized, there is no * active window yet. */ g_print ("%s\n", wnck_window_get_name (window)); }
void show_force_quit_dialog (WnckWindow *win, Time timestamp) { decor_t *d = g_object_get_data (G_OBJECT (win), "decor"); GtkWidget *dialog; gchar *str, *tmp; const gchar *message; if (d->force_quit_dialog) return; tmp = g_markup_escape_text (wnck_window_get_name (win), -1); str = g_strdup_printf (_("The window \"%s\" is not responding."), tmp); g_free (tmp); message = _("Forcing this application to quit will cause you to lose any unsaved changes."); dialog = gtk_message_dialog_new_with_markup (NULL, 0, GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, "<b>%s</b>\n\n%s", str, message); g_free (str); gtk_window_set_icon_name (GTK_WINDOW (dialog), "force-quit"); gtk_dialog_add_buttons (GTK_DIALOG (dialog), _("_Cancel"), GTK_RESPONSE_REJECT, _("_Force Quit"), GTK_RESPONSE_ACCEPT, NULL); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_REJECT); g_signal_connect (G_OBJECT (dialog), "realize", G_CALLBACK (force_quit_dialog_realize), win); g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (force_quit_dialog_response), win); gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); gtk_widget_realize (dialog); gdk_x11_window_set_user_time (gtk_widget_get_window (dialog), timestamp); gtk_widget_show (dialog); d->force_quit_dialog = dialog; }
/** * Sets the caller pointer * @param DockItem* item */ void Preview::init(DockItem* item/*, int &width, int &height, int &windowWidth*/) { if (item == NULL) return; if (item->m_items.size() == 0) return; m_previewtems.clear(); this->m_instancename = item->m_items.at(0)->m_instancename; for (DockItem* child : item->m_items) { if (child->m_window == NULL || child->m_xid == 0) continue; DockItem* newchild = new DockItem(); //the name of window , or a fallback name if no name is available. newchild->m_titlename = wnck_window_get_name(child->m_window); newchild->m_window = child->m_window; newchild->m_xid = child->m_xid; m_previewtems.push_back(newchild); } m_currentIndex = 0; m_initialItemMax = (int) m_previewtems.size(); // Sort by title name int size = (int) m_previewtems.size(); int i, m, j; for (i = 0; i < size - 1; i = i + 1) { m = i; for (j = i + 1; j < size; j = j + 1) { std::string s1 = m_previewtems.at(j)->m_titlename.c_str(); std::string s2 = m_previewtems.at(m)->m_titlename.c_str(); s1 = s1.substr(0, 40); s2 = s2.substr(0, 40); std::string a = Utilities::stringToLower(s1.c_str()); std::string b = Utilities::stringToLower(s2.c_str()); if (a < b) { m = j; } } std::swap(m_previewtems.at(i), m_previewtems.at(m)); } }
static void on_active_window_changed (WnckScreen *screen, WnckWindow *previously_active_window, gpointer data) { WnckWindow *active_window; active_window = wnck_screen_get_active_window (screen); if (active_window) g_print ("active: %s\n", wnck_window_get_name (active_window)); else g_print ("no active window\n"); }
static gboolean on_query_tooltip (GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, GtkTooltip *tooltip, TaskItem *item) { WnckWindow *window = item->priv->window; g_return_val_if_fail (WNCK_IS_WINDOW (window), FALSE); gtk_tooltip_set_text (tooltip, wnck_window_get_name(window)); gtk_tooltip_set_icon (tooltip, wnck_window_get_icon (window)); return TRUE; }
GtkWidget* window_menu_item_new (WnckWindow* window) { WnckApplication* application; GdkPixbuf* pixbuf; GtkWidget* item; GtkWidget* label; gchar * markup; g_return_val_if_fail (WNCK_IS_WINDOW (window), NULL); item = gtk_image_menu_item_new (); application = wnck_window_get_application (window); /* FIXME: track icon changes */ pixbuf = wnck_application_get_icon (application); if (pixbuf) { GtkWidget* image = gtk_image_new_from_pixbuf (pixbuf); gtk_widget_show (image); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); } g_signal_connect (item, "activate", G_CALLBACK (window_item_activated), window); /* FIXME: track name changes */ label = gtk_label_new (NULL); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); markup = g_strdup_printf ("<b>%s</b>\n<small>%s</small>", wnck_application_get_name (application), wnck_window_get_name (window)); gtk_label_set_markup (GTK_LABEL (label), markup); g_free (markup); gtk_widget_show (label); gtk_container_add (GTK_CONTAINER (item), label); return item; }
static void task_item_setup_atk (TaskItem *item) { TaskItemPrivate *priv; GtkWidget *widget; AtkObject *atk; WnckWindow *window; g_return_if_fail (TASK_IS_ITEM (item)); widget = GTK_WIDGET (item); priv = item->priv; window = priv->window; g_return_if_fail (WNCK_IS_WINDOW (window)); atk = gtk_widget_get_accessible (widget); atk_object_set_name (atk, _("Window Task Button")); atk_object_set_description (atk, wnck_window_get_name (window)); atk_object_set_role (atk, ATK_ROLE_PUSH_BUTTON); }
/** * returns the window name */ int c_get_window_name(lua_State *lua) { int top = lua_gettop(lua); if (top != 0) { luaL_error(lua, "get_window_name: %s", no_indata_expected_error); return 0; } char *test = NULL; WnckWindow *window = get_current_window(); if (window) { test = (char*)wnck_window_get_name(window); } else { test = ""; } lua_pushstring(lua, test); // one item returned (the window name as a string) return 1; }
static void utterance_loop(int argc,char *argv[]) { int16 adbuf[4096]; int32 k, fr, ts, rem; char *hyp; cont_ad_t *cont; int count=0,i=1,flag; char word[256]; /* Initialize continuous listening module */ if ((cont = cont_ad_init (ad, ad_read)) == NULL) E_FATAL("cont_ad_init failed\n"); if (ad_start_rec (ad) < 0) E_FATAL("ad_start_rec failed\n"); if (cont_ad_calib (cont) < 0) E_FATAL("cont_ad_calib failed\n"); for (;;) { /* Indicate listening for next utterance */ printf ("READY....\n"); fflush (stdout); fflush (stderr); /* Await data for next utterance */ while ((k = cont_ad_read (cont, adbuf, 4096)) == 0) sleep_msec(200); if (k < 0) E_FATAL("cont_ad_read failed\n"); /* * Non-zero amount of data received; start recognition of new utterance. * NULL argument to uttproc_begin_utt => automatic generation of utterance-id. */ if (uttproc_begin_utt (NULL) < 0) E_FATAL("uttproc_begin_utt() failed\n"); uttproc_rawdata (adbuf, k, 0); printf ("Listening...\n"); fflush (stdout); /* Note timestamp for this first block of data */ ts = cont->read_ts; /* Decode utterance until end (marked by a "long" silence, >1sec) */ for (;;) { /* Read non-silence audio data, if any, from continuous listening module */ if ((k = cont_ad_read (cont, adbuf, 4096)) < 0) E_FATAL("cont_ad_read failed\n"); if (k == 0) { /* * No speech data available; check current timestamp with most recent * speech to see if more than 1 sec elapsed. If so, end of utterance. */ if ((cont->read_ts - ts) > DEFAULT_SAMPLES_PER_SEC) break; } else { /* New speech data received; note current timestamp */ ts = cont->read_ts; } /* * Decode whatever data was read above. NOTE: Non-blocking mode!! * rem = #frames remaining to be decoded upon return from the function. */ rem = uttproc_rawdata (adbuf, k, 0); /* If no work to be done, sleep a bit */ if ((rem == 0) && (k == 0)) sleep_msec (20); } /* * Utterance ended; flush any accumulated, unprocessed A/D data and stop * listening until current utterance completely decoded */ ad_stop_rec (ad); while (ad_read (ad, adbuf, 4096) >= 0); cont_ad_reset (cont); printf ("Stopped listening, please wait...\n"); fflush (stdout); #if 0 /* Power histogram dump (FYI) */ cont_ad_powhist_dump (stdout, cont); #endif /* Finish decoding, obtain and print result */ uttproc_end_utt (); if (uttproc_result (&fr, &hyp, 1) < 0) E_FATAL("uttproc_result failed\n"); /*obtaining the results*/ sscanf (hyp, "%s", word); printf ("%d: %s\n", fr,word); fflush (stdout); win=wnck_screen_get_active_window(scr); tmp=wnck_screen_get_windows(wnck_window_get_screen(win)); i=g_list_index(tmp,win);/*the place value of window in the list*/ printf("<<<<<<<<<<<<<<>>>>>>>>>>>>>>i:%d,%s\n\n\n",i,wnck_window_get_name(win)); count=0; while(tmp!=NULL) { printf("%d:%s\n\n",count,wnck_window_get_name(tmp->data)); tmp=tmp->next;count++; } /*comparison and action for DAKKU */ if(strcmp(word,"PADU")==0) g_spawn_command_line_async("totem --play",NULL); if(strcmp(word,"EMACS")==0) g_spawn_command_line_async("emacs",NULL); if(strcmp(word,"SAMAYAM")==0) g_spawn_command_line_async(DHVANISCRIPT,NULL); if(strcmp(word,"VALAPARATHU")==0) g_spawn_command_line_async("epiphany",NULL); if(strcmp(word,"EAZHUTHIDAM")==0) g_spawn_command_line_async("gedit",NULL); /*Minimizing current active window*/ if (strcmp (word, "CHURUKKU") == 0) wnck_window_minimize(win); /*Moving focus(active window)towards the left of the panel.The active window is changed to the next normal window on the left.effect of alt+tab key press*/ if(strcmp(word,"ADUTHATHU")==0) { win=wnck_screen_get_active_window(scr); tmp=wnck_screen_get_windows(wnck_window_get_screen(win)); while(tmp!=NULL)/*while traces the current active window through the list*/ { printf("tracing:current:%s\n\ntmp:%s\n\n",wnck_window_get_name(win),wnck_window_get_name(tmp->data)); if(tmp->data==win) { printf("BREAKED with tmp:%s\n",wnck_window_get_name(tmp->data)); break; } tmp=tmp->next; } if(tmp==NULL){printf("BULL SHIT GIVE A WINDOW IN THE LIST\n\n");}//exit(1);} if(tmp->next==NULL)/*shifting back to the first window by refreshing the list*/ tmp=wnck_screen_get_windows(wnck_window_get_screen(win)); else tmp=tmp->next; printf("cuow:%s\n\n",wnck_window_get_name(tmp->data)); while(tmp!=NULL) { printf("tmp in while:%s\n\n",wnck_window_get_name(tmp->data)); if(wnck_window_get_window_type(tmp->data)==WNCK_WINDOW_NORMAL) { wnck_window_activate(tmp->data,0); flag=1; break; } else tmp=tmp->next; } if(flag==0) { printf("FLAG==0 DETECTED:\n"); tmp=wnck_screen_get_windows(wnck_window_get_screen(win)); while(tmp!=NULL) { printf("tmp in last while:%s\n",wnck_window_get_name(tmp->data)); if(wnck_window_get_window_type(tmp->data)==WNCK_WINDOW_NORMAL) { wnck_window_activate(tmp->data,0); break; } else tmp=tmp->next; } } } if(strcmp(word,"VALUTHAKKU")==0) { if(wnck_window_get_window_type(win)!= WNCK_WINDOW_NORMAL) { if(wnck_window_get_window_type(wnck_screen_get_previously_active_window(scr))==WNCK_WINDOW_NORMAL) win=wnck_screen_get_previously_active_window(scr); } wnck_window_unminimize(win,0); } while(gtk_events_pending())/*gtk probing and refreshing the win and tmp*/ { gtk_main_iteration(); win=wnck_screen_get_active_window(scr); tmp=wnck_screen_get_windows(wnck_window_get_screen(win)); } /* Resume A/D recording for next utterance */ if (ad_start_rec (ad) < 0) E_FATAL("ad_start_rec failed\n"); } cont_ad_close (cont); }
static void on_active_window_changed (WnckScreen *screen, WnckWindow *old_window, TaskTitle *title) { g_return_if_fail (TASK_IS_TITLE (title)); WnckWindow *act_window = wnck_screen_get_active_window (screen); WnckWindowType type = WNCK_WINDOW_NORMAL; TaskTitlePrivate *priv = title->priv; if (act_window) type = wnck_window_get_window_type (act_window); disconnect_window (title); // Depending on the type and state of the window we adjust the title if(WNCK_IS_WINDOW(act_window)) { if(type == WNCK_WINDOW_DESKTOP) { /* The current window is the desktop so we show the home title if * the user has configured this, otherwise we hide the title */ if (window_picker_applet_get_show_home_title (priv->windowPickerApplet)) { show_home_title(title); } else { hide_title (title); } } else if(wnck_window_is_skip_tasklist (act_window) && type != WNCK_WINDOW_DESKTOP) { /* The current window is not in the task list, we dont change the * current title. */ return; } else if(type == WNCK_WINDOW_DOCK || type == WNCK_WINDOW_SPLASHSCREEN || type == WNCK_WINDOW_MENU) { return; } else { //for all other types if(wnck_window_is_maximized (act_window) && window_picker_applet_get_show_application_title (priv->windowPickerApplet)) { //show normal title of window gtk_label_set_text (GTK_LABEL (priv->label), wnck_window_get_name (act_window)); gtk_image_set_from_icon_name (GTK_IMAGE (priv->button_image), "window-close", GTK_ICON_SIZE_MENU); gtk_widget_set_tooltip_text (GTK_WIDGET (title), wnck_window_get_name (act_window)); gtk_widget_set_tooltip_text (priv->button, _("Close window")); g_signal_connect (act_window, "name-changed", G_CALLBACK (on_name_changed), title); g_signal_connect_after (act_window, "state-changed", G_CALLBACK (on_state_changed), title); gtk_widget_show (priv->grid); priv->window = act_window; } else { hide_title (title); //only show the title for maximized windows } } } else { //its not a window if (task_list_get_desktop_visible (TASK_LIST (window_picker_applet_get_tasks (priv->windowPickerApplet))) && window_picker_applet_get_show_home_title (priv->windowPickerApplet)) { show_home_title(title); } else { //reset the task title and hide it hide_title (title); } } gtk_widget_queue_draw (GTK_WIDGET (title)); }
/* Warning! This function is called very often, so it should only do the most necessary things! */ static void on_name_changed (WnckWindow *controlwindow, WindowckPlugin *wckp) { gint i, n; const gchar *title_text; if (controlwindow && ((wnck_window_get_window_type (controlwindow) != WNCK_WINDOW_DESKTOP) || wckp->prefs->show_on_desktop)) { const gchar *title_color, *title_font, *subtitle_font; gchar **part, *title_markup; title_text = wnck_window_get_name(controlwindow); if (wnck_window_is_active(controlwindow)) { /* window focused */ //~ gtk_widget_set_sensitive(GTK_WIDGET(wckp->title), TRUE); title_color = wckp->prefs->active_text_color; } else { /* window unfocused */ //~ gtk_widget_set_sensitive(GTK_WIDGET(wckp->title), FALSE); title_color = wckp->prefs->inactive_text_color; } title_font = wckp->prefs->title_font; subtitle_font = wckp->prefs->subtitle_font; /* Set tooltips */ if (wckp->prefs->show_tooltips) { gtk_widget_set_tooltip_text(GTK_WIDGET(wckp->title), title_text); } /* get application and instance names */ if (wckp->prefs->full_name && !wckp->prefs->two_lines) { title_markup = g_markup_printf_escaped("<span font=\"%s\" color=\"%s\">%s</span>", title_font, title_color, title_text); } else { /* split title text */ part = g_strsplit (title_text, " - ", 0); n=0; for (i=0; part[i]; i++) n++; if (n > 1) { if (wckp->prefs->two_lines) { gchar *subtitle = malloc( sizeof(gchar) * ( strlen(title_text) + 1 ) ); strcpy (subtitle, part[0]); if (wckp->prefs->full_name) { for (i=1; i < n - 1; i++) { strcat (subtitle, " - "); strcat (subtitle, part[i]); } } title_markup = g_markup_printf_escaped("<span font=\"%s\" color=\"%s\">%s</span><span font=\"%s\" color=\"%s\">\n%s</span>", title_font, title_color, part[n-1], subtitle_font, title_color, subtitle); free (subtitle); } else { title_markup = g_markup_printf_escaped("<span font=\"%s\" color=\"%s\">%s</span>", title_font, title_color, part[n-1]); } } else { title_markup = g_markup_printf_escaped("<span font=\"%s\" color=\"%s\">%s</span>", title_font, title_color, part[0]); } g_strfreev(part); } gtk_label_set_markup(wckp->title, title_markup); if (wckp->prefs->title_alignment == LEFT) { gtk_label_set_justify(wckp->title, GTK_JUSTIFY_LEFT); } else if (wckp->prefs->title_alignment == CENTER) { gtk_label_set_justify(wckp->title, GTK_JUSTIFY_CENTER); } else if (wckp->prefs->title_alignment == RIGHT) { gtk_label_set_justify(wckp->title, GTK_JUSTIFY_RIGHT); } g_free (title_markup); } else { /* hide text */ title_text = ""; gtk_label_set_text(wckp->title, title_text); } }
/* * update_window_decoration_name * * Returns: void * Description: frees the last window name and gets the new one from * wnck. Also checks to see if the name has a length (slight optimization) * and re-creates the pango context to re-render the name */ void update_window_decoration_name (WnckWindow *win) { decor_t *d = g_object_get_data (G_OBJECT (win), "decor"); const gchar *name; glong name_length; PangoLayoutLine *line; if (d->name) { g_free (d->name); d->name = NULL; } /* Only operate if the window name has a length */ name = wnck_window_get_name (win); if (name && (name_length = strlen (name))) { gint w; /* Cairo mode: w = SHRT_MAX */ if (theme_draw_window_decoration != draw_window_decoration) { w = SHRT_MAX; } /* Need to get a minimum width for the name */ else { gint width; wnck_window_get_client_window_geometry (win, NULL, NULL, &width, NULL); w = width - ICON_SPACE - 2 - d->button_width; if (w < 1) w = 1; } /* Set the maximum width for the layout (in case * decoration size < text width) since we * still need to show the buttons and the window name */ pango_layout_set_auto_dir (d->layout, FALSE); pango_layout_set_width (d->layout, w * PANGO_SCALE); pango_layout_set_text (d->layout, name, name_length); line = pango_layout_get_line (d->layout, 0); name_length = line->length; if (pango_layout_get_line_count (d->layout) > 1) { if (name_length < 4) { pango_layout_set_text (d->layout, NULL, 0); return; } d->name = g_strndup (name, name_length); strcpy (d->name + name_length - 3, "..."); } else d->name = g_strndup (name, name_length); /* Truncate the text */ pango_layout_set_text (d->layout, d->name, name_length); } }
// Updates the images according to preferences and the window situation // Warning! This function is called very often, so it should only do the most necessary things! void updateTitle(WTApplet *wtapplet) { WnckWindow *controlledwindow; gchar *title_text, *title_color, *title_font; GdkPixbuf *icon_pixbuf; if (wtapplet->prefs->only_maximized) { controlledwindow = wtapplet->umaxedwindow; } else { controlledwindow = wtapplet->activewindow; } if (controlledwindow == NULL) return; if (controlledwindow == wtapplet->rootwindow) { // we're on desktop if (wtapplet->prefs->hide_on_unmaximized) { // hide everything icon_pixbuf = NULL; title_text = ""; } else { // display "custom" icon/title (TODO: customization via preferences?) icon_pixbuf = gtk_widget_render_icon(GTK_WIDGET(wtapplet),GTK_STOCK_HOME,GTK_ICON_SIZE_MENU,NULL); // This has to be unrefed! title_text = ("Desktop"); } } else { icon_pixbuf = wnck_window_get_icon(controlledwindow); // This only returns a pointer - it SHOULDN'T be unrefed! title_text = (gchar*)wnck_window_get_name(controlledwindow); } // TODO: we need the default font to somehow be the same in both modes if (wtapplet->prefs->custom_style) { // custom style if (controlledwindow == wtapplet->activewindow) { // window focused title_color = wtapplet->prefs->title_active_color; title_font = wtapplet->prefs->title_active_font; } else { // window unfocused title_color = wtapplet->prefs->title_inactive_color; title_font = wtapplet->prefs->title_inactive_font; } } else { // automatic (non-custom) style if (controlledwindow == wtapplet->activewindow) { // window focused title_color = wtapplet->panel_color_fg; title_font = ""; } else { // window unfocused title_color = "#808080"; // inactive title color. best fits for any panel regardless of color title_font = ""; } } // Set tooltips if (wtapplet->prefs->show_tooltips) { gtk_widget_set_tooltip_text (GTK_WIDGET(wtapplet->icon), title_text); gtk_widget_set_tooltip_text (GTK_WIDGET(wtapplet->title), title_text); } title_text = g_markup_printf_escaped("<span font=\"%s\" color=\"%s\">%s</span>", title_font, title_color, title_text); // Apply markup to label widget gtk_label_set_markup(GTK_LABEL(wtapplet->title), title_text); g_free(title_text); if (icon_pixbuf == NULL) { gtk_image_clear(wtapplet->icon); } else { // We're updating window info (Careful! We've had pixbuf memory leaks here) GdkPixbuf *ipb1 = gdk_pixbuf_scale_simple(icon_pixbuf, ICON_WIDTH, ICON_HEIGHT, GDK_INTERP_BILINEAR); if (controlledwindow == wtapplet->rootwindow) g_object_unref(icon_pixbuf); //this is stupid beyond belief, thanks to the retarded GTK framework GdkPixbuf *ipb2 = gdk_pixbuf_rotate_simple(ipb1, wtapplet->angle); g_object_unref(ipb1); // Unref ipb1 to get it cleared from memory (we still need ipb2) // Saturate icon when window is not focused if (controlledwindow != wtapplet->activewindow) gdk_pixbuf_saturate_and_pixelate(ipb2, ipb2, 0, FALSE); // Apply pixbuf to icon widget gtk_image_set_from_pixbuf(wtapplet->icon, ipb2); g_object_unref(ipb2); // Unref ipb2 to get it cleared from memory } }
/* * wnck_window_get_real_name * * Returns: const char * or NULL * Description: Wrapper function to either get the name of the window or * return NULL */ static const char * wnck_window_get_real_name (WnckWindow *win) { return wnck_window_has_name (win) ? wnck_window_get_name (win) : NULL; }
/** * ww_find_neighbour * @screen: * @windows: * @active: * @direction: * * Return value: The neighbouring window from @windows in the given direction * or %NULL in case no window is found or @active is %NULL */ WnckWindow* ww_find_neighbour (WnckScreen *screen, GList *windows, WnckWindow *active, WwDirection direction) { WnckWindow *neighbour; GList *next; int ax, ay, aw, ah; /* active window geometry */ int wx, wy; /* geometry for currently checked window */ int nx, ny; /* geometry of neighbour */ double wdist, ndist; /* distance to active window */ neighbour = NULL; g_return_val_if_fail (WNCK_IS_SCREEN(screen), NULL); if (g_list_length(windows) == 0) { return NULL; } /* If there is no active window, do nothing */ if (active == NULL || wnck_window_is_skip_tasklist (active)) { g_debug ("No active window"); return NULL; } nx = ny = 0; ndist = 100000; wnck_window_get_geometry (active, &ax, &ay, &aw, &ah); g_debug("Active window '%s' (%d, %d) @ %d x %d", wnck_window_get_name (active), ax, ay, aw, ah); /* Set ax and ay to the center of grav. for active */ ww_window_center (active, &ax, &ay); if ( direction == LEFT ) { for ( next = windows; next; next = next->next ) { ww_window_center (WNCK_WINDOW (next->data), &wx, &wy); wdist = ww_y_weighted_distance (wx, wy, ax, ay); if ( wx < ax ) { if ( wdist < ndist ) { neighbour = WNCK_WINDOW (next->data); ndist = wdist; } } } } else if ( direction == RIGHT ) { for ( next = windows; next; next = next->next ) { ww_window_center (WNCK_WINDOW (next->data), &wx, &wy); wdist = ww_y_weighted_distance (wx, wy, ax, ay); if ( wx > ax ) { if ( wdist < ndist ) { neighbour = WNCK_WINDOW (next->data); ndist = wdist; } } } } else if ( direction == DOWN ) { for ( next = windows; next; next = next->next ) { ww_window_center (WNCK_WINDOW (next->data), &wx, &wy); wdist = ww_x_weighted_distance (wx, wy, ax, ay); if ( wy > ay ) { if ( wdist < ndist ) { neighbour = WNCK_WINDOW (next->data); ndist = wdist; } } } } else if ( direction == UP ) { for ( next = windows; next; next = next->next ) { ww_window_center (WNCK_WINDOW (next->data), &wx, &wy); wdist = ww_x_weighted_distance (wx, wy, ax, ay); if ( wy < ay ) { if ( wdist < ndist ) { neighbour = WNCK_WINDOW (next->data); ndist = wdist; } } } } if (neighbour) g_debug ("Found neighbour '%s'", wnck_window_get_name (neighbour)); return neighbour; }