/* ---------------------------------------------------------------------------------------------------- */ /* these functions are based on code from libwnck (LGPLv2) */
static gboolean get_window_list (GdkDisplay *display,
Display *xdisplay,
Window xwindow,
Atom atom,
Window **windows, int *len);
staticchar* get_utf8_property (GdkDisplay *display,
Display *xdisplay,
Window xwindow,
Atom atom);
static gboolean get_cardinal (GdkDisplay *display,
Display *xdisplay,
Window xwindow,
Atom atom, int *val);
static gboolean read_rgb_icon (GdkDisplay *display,
Display *xdisplay,
Window xwindow, int ideal_width, int ideal_height, int *width, int *height,
guchar **pixdata);
static gboolean
get_cardinal (GdkDisplay *display,
Display *xdisplay,
Window xwindow,
Atom atom, int *val)
{
Atom type; int format;
gulong nitems;
gulong bytes_after;
gulong *num; int err, result;
static gboolean
find_largest_sizes (gulong *data,
gulong nitems, int *width, int *height)
{
*width = 0;
*height = 0;
while (nitems > 0)
{ int w, h;
if (nitems < 3) returnFALSE; /* no space for w, h */
w = data[0];
h = data[1];
if (nitems < ((w * h) + 2)) returnFALSE; /* not enough data */
*width = MAX (w, *width);
*height = MAX (h, *height);
data += (w * h) + 2;
nitems -= (w * h) + 2;
}
returnTRUE;
}
static gboolean
find_best_size (gulong *data,
gulong nitems, int ideal_width, int ideal_height, int *width, int *height,
gulong **start)
{ int best_w; int best_h;
gulong *best_start; int max_width, max_height;
*width = 0;
*height = 0;
*start = NULL;
if (!find_largest_sizes (data, nitems, &max_width, &max_height)) returnFALSE;
if (ideal_width < 0)
ideal_width = max_width; if (ideal_height < 0)
ideal_height = max_height;
best_w = 0;
best_h = 0;
best_start = NULL;
while (nitems > 0)
{ int w, h;
gboolean replace;
replace = FALSE;
if (nitems < 3) returnFALSE; /* no space for w, h */
w = data[0];
h = data[1];
if (nitems < ((w * h) + 2)) break; /* not enough data */
if (best_start == NULL)
{
replace = TRUE;
} else
{ /* work with averages */ constint ideal_size = (ideal_width + ideal_height) / 2; int best_size = (best_w + best_h) / 2; int this_size = (w + h) / 2;
/* larger than desired is always better than smaller */ if (best_size < ideal_size &&
this_size >= ideal_size)
replace = TRUE; /* if we have too small, pick anything bigger */ elseif (best_size < ideal_size &&
this_size > best_size)
replace = TRUE; /* if we have too large, pick anything smaller *butstill>=theideal
*/ elseif (best_size > ideal_size &&
this_size >= ideal_size &&
this_size < best_size)
replace = TRUE;
}
if (replace)
{
best_start = data + 2;
best_w = w;
best_h = h;
}
static gboolean
read_rgb_icon (GdkDisplay *display,
Display *xdisplay,
Window xwindow, int ideal_width, int ideal_height, int *width, int *height,
guchar **pixdata)
{
Atom type; int format;
gulong nitems;
gulong bytes_after; int result, err;
gulong *data;
gulong *best; int w, h;
gdk_x11_display_error_trap_push (display);
type = None;
data = NULL;
result = XGetWindowProperty (xdisplay,
xwindow,
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_ICON"), 0, G_MAXLONG, False, XA_CARDINAL, &type, &format, &nitems,
&bytes_after, (void*)&data);
/* /proc/<pid>/environ in Linux is split at '\0' points, g_strsplit() can't handle that... */
n = 0; while (TRUE)
{ if (n >= env_len || env[n] == '\0') break;
if (g_str_has_prefix (env + n, key) && (*(env + n + key_len) == '='))
{
ret = g_strdup (env + n + key_len + 1);
/* check for $WINDOWID (set by terminals) and see if we can get the title that way */
windowid_value = pid_get_env (pid, "WINDOWID"); if (windowid_value != NULL)
{ char *endp;
staticconstchar *well_known_commands[] =
{ /* translators: this string is a name for the 'less' command */ "less", N_("Terminal Pager"), "top", N_("Top Command"), "bash", N_("Bourne Again Shell"), "sh", N_("Bourne Shell"), "zsh", N_("Z Shell"),
NULL,
};
if (!GDK_IS_X11_DISPLAY (context->display)) returnFALSE;
/* We perform two different lookups for name and icon size.. this is *becausewewantthenamefromthewindowwithWINDOWIDandthis *normallydoesnotgiveyouanicon * *(thecanonicalexampleisatabingnome-terminal-theshell/commandrunning *intheshellwillhaveWINDOWIDset-butthiswindowwon'thaveanicon-so *wewanttocontinueupuntilthegnome-terminalwindowsowecangetthaticon)
*/
/* if we didn't manage to find the name via X, fall back to the basename *ofthefirstelementofthecommandlineand,formaximumgeek-comfort, *mapafewwell-knowncommandstopropertranslatednames
*/ if (*out_name == NULL && *out_command_line != NULL &&
strlen (*out_command_line) > 0 && (*out_command_line)[0] != ' ')
{
guint n; char *s; char *p;
/* find the first character after the first argument */
s = strchr (*out_command_line, ' '); if (s == NULL)
s = *out_command_line + strlen (*out_command_line);
for (p = s; p > *out_command_line; p--)
{ if (*p == '/')
{
p++; break;
}
}
*out_name = g_strndup (p, s - p);
for (n = 0; well_known_commands[n] != NULL; n += 2)
{ /* sometimes the command is prefixed with a -, e.g. '-bash' instead *of'bash'-handlethataswell
*/ if ((strcmp (well_known_commands[n], *out_name) == 0) ||
((*out_name)[0] == '-' && (strcmp (well_known_commands[n], (*out_name) + 1) == 0)))
{
g_free (*out_name);
*out_name = g_strdup (_(well_known_commands[n+1])); break;
}
}
}
if (kill ((pid_t) pid, SIGTERM) != 0)
{ int errsv = errno;
/* TODO: On EPERM, we could use a setuid helper using polkit (very easy to implement *viapkexec(1))toallowtheusertoe.g.authenticatetogaintheauthorization *tokilltheprocess.Butthat'snothowthingscurrentlywork.
*/
ret = FALSE;
g_set_error (error,
G_IO_ERROR,
g_io_error_from_errno (errsv),
_("Cannot end process with PID %d: %s"),
pid,
g_strerror (errsv));
}
return ret;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-07-03)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.