Skip to content

Instantly share code, notes, and snippets.

@scriptum
Created March 4, 2015 17:26
Show Gist options
  • Select an option

  • Save scriptum/08f6ae9eddae29cb9c2e to your computer and use it in GitHub Desktop.

Select an option

Save scriptum/08f6ae9eddae29cb9c2e to your computer and use it in GitHub Desktop.
xfwm4
gboolean
sessionLoadWindowStates (const gchar * filename)
{
FILE *f;
gchar s[4096], s1[4096];
gint i, pos, pos1;
unsigned long w;
g_return_val_if_fail (filename != NULL, FALSE);
if ((f = fopen (filename, "r")))
{
while (fgets (s, sizeof (s), f))
{
sscanf (s, "%4000s", s1);
if (!strcmp (s1, "[CLIENT]"))
{
sscanf (s, "%*s 0x%lx", &w);
num_match++;
matches = g_realloc (matches, sizeof (Match) * num_match);
matches[num_match - 1].win = w;
matches[num_match - 1].client_id = NULL;
matches[num_match - 1].res_name = NULL;
matches[num_match - 1].res_class = NULL;
matches[num_match - 1].window_role = NULL;
matches[num_match - 1].wm_name = NULL;
matches[num_match - 1].wm_command_count = 0;
matches[num_match - 1].wm_command = NULL;
matches[num_match - 1].x = 0;
matches[num_match - 1].y = 0;
matches[num_match - 1].width = 100;
matches[num_match - 1].height = 100;
matches[num_match - 1].old_x = matches[num_match - 1].x;
matches[num_match - 1].old_y = matches[num_match - 1].y;
matches[num_match - 1].old_width = matches[num_match - 1].width;
matches[num_match - 1].old_height = matches[num_match - 1].height;
matches[num_match - 1].desktop = 0;
matches[num_match - 1].screen = 0;
matches[num_match - 1].used = FALSE;
matches[num_match - 1].flags = 0;
}
else if (!strcmp (s1, "[GEOMETRY]"))
{
sscanf (s, "%*s (%i,%i,%i,%i)", &matches[num_match - 1].x,
&matches[num_match - 1].y, &matches[num_match - 1].width,
&matches[num_match - 1].height);
}
else if (!strcmp (s1, "[GEOMETRY-MAXIMIZED]"))
{
sscanf (s, "%*s (%i,%i,%i,%i)", &matches[num_match - 1].old_x,
&matches[num_match - 1].old_y,
&matches[num_match - 1].old_width,
&matches[num_match - 1].old_height);
}
else if (!strcmp (s1, "[SCREEN]"))
{
sscanf (s, "%*s %i", &matches[num_match - 1].screen);
}
else if (!strcmp (s1, "[DESK]"))
{
sscanf (s, "%*s %i", &matches[num_match - 1].desktop);
}
else if (!strcmp (s1, "[CLIENT_LEADER]"))
{
sscanf (s, "%*s 0x%lx",
&matches[num_match - 1].client_leader);
}
else if (!strcmp (s1, "[FLAGS]"))
{
sscanf (s, "%*s 0x%lx", &matches[num_match - 1].flags);
}
else if (!strcmp (s1, "[CLIENT_ID]"))
{
sscanf (s, "%*s %[^\n]", s1);
matches[num_match - 1].client_id = strdup (s1);
}
else if (!strcmp (s1, "[WINDOW_ROLE]"))
{
sscanf (s, "%*s %[^\n]", s1);
matches[num_match - 1].window_role = strdup (s1);
}
else if (!strcmp (s1, "[RES_NAME]"))
{
sscanf (s, "%*s %[^\n]", s1);
matches[num_match - 1].res_name = strdup (s1);
}
else if (!strcmp (s1, "[RES_CLASS]"))
{
sscanf (s, "%*s %[^\n]", s1);
matches[num_match - 1].res_class = strdup (s1);
}
else if (!strcmp (s1, "[WM_NAME]"))
{
sscanf (s, "%*s %[^\n]", s1);
matches[num_match - 1].wm_name = strdup (s1);
}
else if (!strcmp (s1, "[WM_COMMAND]"))
{
sscanf (s, "%*s (%i)%n", &matches[num_match - 1].wm_command_count, &pos);
matches[num_match - 1].wm_command = g_new (gchar *, matches[num_match - 1].wm_command_count + 1);
for (i = 0; i < matches[num_match - 1].wm_command_count; i++)
{
gchar *substring;
substring = getsubstring (s + pos, &pos1);
pos += pos1;
matches[num_match - 1].wm_command[i] = unescape_quote (substring);
g_free (substring);
}
matches[num_match - 1].wm_command[matches[num_match - 1].wm_command_count] = NULL;
}
}
fclose (f);
return TRUE;
}
return FALSE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment