Provide control over match conditions for saved settings.

SVN revision: 16871
This commit is contained in:
Kim Woelders 2005-09-23 16:12:13 +00:00
parent 4d5612bfe1
commit ccb844716d
9 changed files with 259 additions and 123 deletions

14
src/E.h
View File

@ -326,7 +326,6 @@ int Esnprintf(va_alist);
typedef struct _ewin EWin; typedef struct _ewin EWin;
typedef struct _dialog Dialog; typedef struct _dialog Dialog;
typedef struct _ditem DItem; typedef struct _ditem DItem;
typedef struct _snapshot Snapshot;
typedef struct _group Group; typedef struct _group Group;
typedef struct _background Background; typedef struct _background Background;
typedef struct _ecursor ECursor; typedef struct _ecursor ECursor;
@ -1627,19 +1626,6 @@ void MaxHeight(EWin * ewin, const char *resize_type);
/* slideouts.c */ /* slideouts.c */
int SlideoutsConfigLoad(FILE * fs); int SlideoutsConfigLoad(FILE * fs);
/* snaps.c */
void Real_SaveSnapInfo(int dumval, void *dumdat);
void LoadSnapInfo(void);
void SaveSnapInfo(void);
void SpawnSnappedCmds(void);
void SnapshotEwinMatch(EWin * ewin);
void SnapshotEwinUnmatch(EWin * ewin);
void SnapshotEwinUpdate(EWin * ewin, unsigned int flags);
void SnapshotEwinParse(EWin * ewin, const char *params);
void SettingsRemember(void);
extern const char SnapIpcText[];
void SnapIpcFunc(const char *params, Client * c);
/* sound.c */ /* sound.c */
void SoundPlay(const char *name); void SoundPlay(const char *name);

View File

@ -563,7 +563,7 @@ Adopt(EWin * ewin)
MatchEwinToSM(ewin); MatchEwinToSM(ewin);
#endif #endif
WindowMatchEwinOps(ewin); /* Window matches */ WindowMatchEwinOps(ewin); /* Window matches */
SnapshotEwinMatch(ewin); /* Saved settings */ SnapshotsApplyToEwin(ewin); /* Saved settings */
if (!EwinIsInternal(ewin) && Mode.wm.startup) if (!EwinIsInternal(ewin) && Mode.wm.startup)
EHintsGetInfo(ewin); /* E restart hints */ EHintsGetInfo(ewin); /* E restart hints */

View File

@ -32,6 +32,8 @@ struct _desk;
typedef struct _ewin EWin; typedef struct _ewin EWin;
#endif #endif
struct _snapshot;
struct _ewin struct _ewin
{ {
EObj o; EObj o;
@ -186,7 +188,7 @@ struct _ewin
int shape_x, shape_y, shape_w, shape_h; int shape_x, shape_y, shape_w, shape_h;
int req_x, req_y; int req_x, req_y;
Snapshot *snap; struct _snapshot *snap;
int head; /* Unused? */ int head; /* Unused? */
int vx, vy; /* Position in virtual root */ int vx, vy; /* Position in virtual root */

View File

@ -27,6 +27,7 @@
#include "eobj.h" #include "eobj.h"
#include "ewins.h" #include "ewins.h"
#include "ewin-ops.h" #include "ewin-ops.h"
#include "snaps.h"
#include "xwin.h" #include "xwin.h"
#include <ctype.h> #include <ctype.h>

View File

@ -24,6 +24,7 @@
#include "E.h" #include "E.h"
#include "desktops.h" #include "desktops.h"
#include "emodule.h" #include "emodule.h"
#include "snaps.h"
#include "timestamp.h" #include "timestamp.h"
#include "xwin.h" #include "xwin.h"
#include <sys/utsname.h> #include <sys/utsname.h>

View File

@ -22,6 +22,7 @@
*/ */
#include "E.h" #include "E.h"
#include "emodule.h" #include "emodule.h"
#include "snaps.h"
/*********************************************************************** /***********************************************************************
* *** should all go elsewhere *** * *** should all go elsewhere ***

View File

@ -25,6 +25,7 @@
#include "ecore-e16.h" #include "ecore-e16.h"
#include "emodule.h" #include "emodule.h"
#include "ewins.h" #include "ewins.h"
#include "snaps.h"
#include "xwin.h" #include "xwin.h"
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>

View File

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2000-2005 Carsten Haitzler, Geoff Harrison and various contributors * Copyright (C) 2000-2005 Carsten Haitzler, Geoff Harrison
* and various contributors
* Copyright (C) 2004-2005 Kim Woelders * Copyright (C) 2004-2005 Kim Woelders
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
@ -33,8 +34,10 @@ struct _snapshot
char *win_title; char *win_title;
char *win_name; char *win_name;
char *win_class; char *win_class;
char *win_role;
EWin *used; EWin *used;
char track_changes; char track_changes;
unsigned int match_flags;
unsigned int use_flags; unsigned int use_flags;
char *border_name; char *border_name;
@ -65,7 +68,7 @@ SnapshotCreate(const char *name)
sn = Ecalloc(1, sizeof(Snapshot)); sn = Ecalloc(1, sizeof(Snapshot));
sn->name = Estrdup(name); sn->name = Estrdup(name);
AddItemEnd(sn, sn->name, 0, LIST_TYPE_SNAPSHOT); AddItemEnd(sn, NULL, 0, LIST_TYPE_SNAPSHOT);
return sn; return sn;
} }
@ -89,6 +92,8 @@ SnapshotDestroy(Snapshot * sn)
Efree(sn->win_name); Efree(sn->win_name);
if (sn->win_class) if (sn->win_class)
Efree(sn->win_class); Efree(sn->win_class);
if (sn->win_role)
Efree(sn->win_role);
if (sn->border_name) if (sn->border_name)
Efree(sn->border_name); Efree(sn->border_name);
if (sn->cmd) if (sn->cmd)
@ -103,15 +108,24 @@ SnapshotDestroy(Snapshot * sn)
* a <name>-<pid>-<something>-<time> like thing. * a <name>-<pid>-<something>-<time> like thing.
* Is this even ICCCM compliant? * Is this even ICCCM compliant?
*/ */
static const char * static char *
SnapGetRole(const char *role, char *buf, int len) SnapGetRole(const char *role, char *buf, int len)
{ {
int l1, l2; int l1, l2;
if (!role)
return NULL;
l1 = strlen(role); l1 = strlen(role);
if (l1 >= len) if (l1 >= len)
l1 = len - 1; l1 = len - 1;
l2 = strcspn(role, "-0123456789");
for (l2 = l1; l2 > 0; l2--)
{
if (role[l2 - 1] != '-' &&
!(role[l2 - 1] >= '0' && role[l2 - 1] <= '9'))
break;
}
if (l1 - l2 > 8) if (l1 - l2 > 8)
l1 = l2; l1 = l2;
memcpy(buf, role, l1); memcpy(buf, role, l1);
@ -120,82 +134,124 @@ SnapGetRole(const char *role, char *buf, int len)
return buf; return buf;
} }
/* Format the window identifier string */ #define SEQ(s1, s2) ((s1) && (s2) && !strcmp(s1, s2))
static int static int
SnapEwinMakeID(EWin * ewin, char *buf, int len) SnapshotEwinMatch(Snapshot * sn, EWin * ewin)
{ {
char s[256]; char buf[256], *s;
if ((ewin->icccm.wm_role) && (ewin->icccm.wm_res_name) /* Don't allow matching anything */
&& (ewin->icccm.wm_res_class)) if (!sn->match_flags)
Esnprintf(buf, len, "%s.%s:%s", ewin->icccm.wm_res_name, return 0;
ewin->icccm.wm_res_class,
SnapGetRole(ewin->icccm.wm_role, s, sizeof(s)));
else if ((ewin->icccm.wm_res_name) && (ewin->icccm.wm_res_class))
Esnprintf(buf, len, "%s.%s", ewin->icccm.wm_res_name,
ewin->icccm.wm_res_class);
else if (ewin->icccm.wm_name)
Esnprintf(buf, len, "TITLE.%s", ewin->icccm.wm_name);
else
return -1;
return 0; if (sn->match_flags & SNAP_MATCH_TITLE
&& !SEQ(sn->win_title, ewin->icccm.wm_name))
return 0;
if (sn->match_flags & SNAP_MATCH_NAME
&& !SEQ(sn->win_name, ewin->icccm.wm_res_name))
return 0;
if (sn->match_flags & SNAP_MATCH_CLASS
&& !SEQ(sn->win_class, ewin->icccm.wm_res_class))
return 0;
if (sn->match_flags & SNAP_MATCH_ROLE)
{
s = SnapGetRole(ewin->icccm.wm_role, buf, sizeof(buf));
if (!SEQ(sn->win_role, s))
return 0;
}
/* Match! */
return 1;
} }
/* find a snapshot state that applies to this ewin */ /* find a snapshot state that applies to this ewin */
static Snapshot * static Snapshot *
SnapshotEwinFind(EWin * ewin) SnapshotEwinFind(EWin * ewin)
{ {
Snapshot *sn; Snapshot **lst, *sn;
char buf[4096]; int i, num;
if (ewin->snap) if (ewin->snap)
return ewin->snap; return ewin->snap;
if (SnapEwinMakeID(ewin, buf, sizeof(buf))) lst = (Snapshot **) ListItemType(&num, LIST_TYPE_SNAPSHOT);
if (!lst)
return NULL; return NULL;
sn = FindItem(buf, 0, LIST_FINDBY_BOTH, LIST_TYPE_SNAPSHOT); for (i = 0; i < num; i++)
if (sn)
{ {
ListChangeItemID(LIST_TYPE_SNAPSHOT, sn, 1); sn = lst[i];
sn->used = ewin;
}
if (sn->used)
continue;
if (!SnapshotEwinMatch(sn, ewin))
continue;
if (!(sn->match_flags & SNAP_MATCH_MULTIPLE))
sn->used = ewin;
goto done;
}
sn = NULL;
done:
Efree(lst);
return sn; return sn;
} }
#define ST(s) ((s) ? (s) : "")
/* find a snapshot state that applies to this ewin Or if that doesnt exist */ /* find a snapshot state that applies to this ewin Or if that doesnt exist */
/* create a new one */ /* create a new one */
static Snapshot * static Snapshot *
SnapshotEwinGet(EWin * ewin) SnapshotEwinGet(EWin * ewin, unsigned int match_flags)
{ {
Snapshot *sn; Snapshot *sn;
char buf[4096]; char buf[1024], *s;
sn = SnapshotEwinFind(ewin); sn = SnapshotEwinFind(ewin);
if (sn) if (sn)
return sn; return sn;
if (SnapEwinMakeID(ewin, buf, sizeof(buf))) /* Fix me - put back the old window ID string */
sn = SnapshotCreate(NULL);
if (!sn)
return NULL; return NULL;
sn = SnapshotCreate(buf); sn->match_flags = match_flags;
ListChangeItemID(LIST_TYPE_SNAPSHOT, sn, 1); if (match_flags & SNAP_MATCH_TITLE)
if ((ewin->icccm.wm_res_name) && (ewin->icccm.wm_res_class)) sn->win_title = Estrdup(ewin->icccm.wm_name);
if (match_flags & SNAP_MATCH_NAME)
sn->win_name = Estrdup(ewin->icccm.wm_res_name);
if (match_flags & SNAP_MATCH_CLASS)
sn->win_class = Estrdup(ewin->icccm.wm_res_class);
if (match_flags & SNAP_MATCH_ROLE)
{ {
sn->win_title = NULL; s = SnapGetRole(ewin->icccm.wm_role, buf, sizeof(buf));
sn->win_name = Estrdup(ewin->icccm.wm_res_name); sn->win_role = Estrdup(s);
sn->win_class = Estrdup(ewin->icccm.wm_res_class);
} }
else
/* Set the snap name. Has no particular significance. */
if ((sn->win_name || sn->win_class) && sn->win_role)
Esnprintf(buf, sizeof(buf), "%s.%s:%s", ST(sn->win_name),
ST(sn->win_class), sn->win_role);
else if (sn->win_name || sn->win_class)
Esnprintf(buf, sizeof(buf), "%s.%s", ST(sn->win_name), ST(sn->win_class));
else if (sn->win_title)
Esnprintf(buf, sizeof(buf), "TITLE.%s", sn->win_title);
else /* We should not go here */
Esnprintf(buf, sizeof(buf), "TITLE.%s", ewin->icccm.wm_name);
sn->name = Estrdup(buf);
if (!(sn->match_flags & SNAP_MATCH_MULTIPLE))
{ {
sn->win_title = Estrdup(ewin->icccm.wm_name); sn->used = ewin;
sn->win_name = NULL; ewin->snap = sn;
sn->win_class = NULL;
} }
sn->used = ewin;
ewin->snap = sn;
return sn; return sn;
} }
@ -318,7 +374,7 @@ SnapEwinGroups(Snapshot * sn, EWin * ewin, char onoff)
{ {
sn = gwins[i]->snap; sn = gwins[i]->snap;
if (!sn) if (!sn)
sn = SnapshotEwinGet(gwins[i]); sn = SnapshotEwinGet(gwins[i], SNAP_MATCH_DEFAULT);
if (sn) if (sn)
{ {
if (sn->groups) if (sn->groups)
@ -405,23 +461,24 @@ SnapEwinUpdate(Snapshot * sn, EWin * ewin, unsigned int flags)
} }
static void static void
SnapshotEwinSet(EWin * ewin, unsigned int flags) SnapshotEwinSet(EWin * ewin, unsigned int match_flags, unsigned int use_flags)
{ {
Snapshot *sn; Snapshot *sn;
/* Quit if nothing to be saved */ /* Quit if nothing to be saved */
if (!(flags & SNAP_USE_ALL)) if (!match_flags || !(use_flags & SNAP_USE_ALL))
return; return;
sn = SnapshotEwinGet(ewin); sn = SnapshotEwinGet(ewin, match_flags);
if (!sn) if (!sn)
return; return;
if (flags & SNAP_AUTO) if (use_flags & SNAP_AUTO)
sn->track_changes = 1; sn->track_changes = 1;
sn->use_flags = flags & SNAP_USE_ALL; sn->use_flags = use_flags & SNAP_USE_ALL;
SnapEwinUpdate(sn, ewin, flags);
SnapEwinUpdate(sn, ewin, use_flags);
} }
void void
@ -456,6 +513,15 @@ SnapshotEwinRemove(EWin * ewin)
typedef struct typedef struct
{ {
Window client; Window client;
struct
{
char title;
char name;
char class;
char role;
} match;
char track_changes; char track_changes;
char snap_border; char snap_border;
char snap_desktop; char snap_desktop;
@ -481,7 +547,7 @@ CB_ApplySnap(Dialog * d, int val, void *data __UNUSED__)
{ {
EWin *ewin; EWin *ewin;
SnapDlgData *sd = DialogGetData(d); SnapDlgData *sd = DialogGetData(d);
unsigned int use_flags; unsigned int match_flags, use_flags;
if (val >= 2 || !sd) if (val >= 2 || !sd)
goto done; goto done;
@ -492,6 +558,19 @@ CB_ApplySnap(Dialog * d, int val, void *data __UNUSED__)
SnapshotEwinRemove(ewin); SnapshotEwinRemove(ewin);
match_flags = 0;
if (sd->match.title)
match_flags |= SNAP_MATCH_TITLE;
if (sd->match.name)
match_flags |= SNAP_MATCH_NAME;
if (sd->match.class)
match_flags |= SNAP_MATCH_CLASS;
if (sd->match.role)
match_flags |= SNAP_MATCH_ROLE;
if (!match_flags)
goto done;
use_flags = 0; use_flags = 0;
if (sd->track_changes) if (sd->track_changes)
use_flags |= SNAP_AUTO; use_flags |= SNAP_AUTO;
@ -524,7 +603,10 @@ CB_ApplySnap(Dialog * d, int val, void *data __UNUSED__)
if (sd->snap_group) if (sd->snap_group)
use_flags |= SNAP_USE_GROUPS; use_flags |= SNAP_USE_GROUPS;
SnapshotEwinSet(ewin, use_flags); if (!use_flags)
goto done;
SnapshotEwinSet(ewin, match_flags, use_flags);
done: done:
if (sd && val == 2) if (sd && val == 2)
@ -587,6 +669,11 @@ SnapshotEwinDialog(EWin * ewin)
sn = ewin->snap; sn = ewin->snap;
if (sn) if (sn)
{ {
sd->match.title = (sn->match_flags & SNAP_MATCH_TITLE) != 0;
sd->match.name = (sn->match_flags & SNAP_MATCH_NAME) != 0;
sd->match.class = (sn->match_flags & SNAP_MATCH_CLASS) != 0;
sd->match.role = (sn->match_flags & SNAP_MATCH_ROLE) != 0;
if (sn->track_changes) if (sn->track_changes)
sd->track_changes = 1; sd->track_changes = 1;
if (sn->use_flags & SNAP_USE_BORDER) if (sn->use_flags & SNAP_USE_BORDER)
@ -618,12 +705,26 @@ SnapshotEwinDialog(EWin * ewin)
if (sn->use_flags & SNAP_USE_GROUPS) if (sn->use_flags & SNAP_USE_GROUPS)
sd->snap_group = 1; sd->snap_group = 1;
} }
else
{
if (ewin->icccm.wm_res_name)
{
sd->match.name = 1;
sd->match.class = 1;
sd->match.role = ewin->icccm.wm_role != NULL;
}
else
{
sd->match.title = ewin->icccm.wm_name != NULL;
}
}
di = DialogAddItem(table, DITEM_TEXT); di = DialogAddItem(table, DITEM_CHECKBUTTON);
DialogItemSetPadding(di, 2, 2, 2, 2); DialogItemSetPadding(di, 2, 2, 2, 2);
DialogItemSetFill(di, 1, 0); DialogItemSetFill(di, 1, 0);
DialogItemSetAlign(di, 0, 512); DialogItemSetAlign(di, 0, 512);
DialogItemSetText(di, _("Title:")); DialogItemSetText(di, _("Title:"));
DialogItemCheckButtonSetPtr(di, &sd->match.title);
di = DialogAddItem(table, DITEM_TEXT); di = DialogAddItem(table, DITEM_TEXT);
DialogItemSetColSpan(di, 3); DialogItemSetColSpan(di, 3);
@ -634,11 +735,12 @@ SnapshotEwinDialog(EWin * ewin)
if (ewin->icccm.wm_res_name) if (ewin->icccm.wm_res_name)
{ {
di = DialogAddItem(table, DITEM_TEXT); di = DialogAddItem(table, DITEM_CHECKBUTTON);
DialogItemSetPadding(di, 2, 2, 2, 2); DialogItemSetPadding(di, 2, 2, 2, 2);
DialogItemSetFill(di, 1, 0); DialogItemSetFill(di, 1, 0);
DialogItemSetAlign(di, 0, 512); DialogItemSetAlign(di, 0, 512);
DialogItemSetText(di, _("Name:")); DialogItemSetText(di, _("Name:"));
DialogItemCheckButtonSetPtr(di, &sd->match.name);
di = DialogAddItem(table, DITEM_TEXT); di = DialogAddItem(table, DITEM_TEXT);
DialogItemSetColSpan(di, 3); DialogItemSetColSpan(di, 3);
@ -650,11 +752,12 @@ SnapshotEwinDialog(EWin * ewin)
if (ewin->icccm.wm_res_class) if (ewin->icccm.wm_res_class)
{ {
di = DialogAddItem(table, DITEM_TEXT); di = DialogAddItem(table, DITEM_CHECKBUTTON);
DialogItemSetPadding(di, 2, 2, 2, 2); DialogItemSetPadding(di, 2, 2, 2, 2);
DialogItemSetFill(di, 1, 0); DialogItemSetFill(di, 1, 0);
DialogItemSetAlign(di, 0, 512); DialogItemSetAlign(di, 0, 512);
DialogItemSetText(di, _("Class:")); DialogItemSetText(di, _("Class:"));
DialogItemCheckButtonSetPtr(di, &sd->match.class);
di = DialogAddItem(table, DITEM_TEXT); di = DialogAddItem(table, DITEM_TEXT);
DialogItemSetColSpan(di, 3); DialogItemSetColSpan(di, 3);
@ -664,6 +767,23 @@ SnapshotEwinDialog(EWin * ewin)
DialogItemSetText(di, ewin->icccm.wm_res_class); DialogItemSetText(di, ewin->icccm.wm_res_class);
} }
if (ewin->icccm.wm_role)
{
di = DialogAddItem(table, DITEM_CHECKBUTTON);
DialogItemSetPadding(di, 2, 2, 2, 2);
DialogItemSetFill(di, 1, 0);
DialogItemSetAlign(di, 0, 512);
DialogItemSetText(di, _("Role:"));
DialogItemCheckButtonSetPtr(di, &sd->match.role);
di = DialogAddItem(table, DITEM_TEXT);
DialogItemSetColSpan(di, 3);
DialogItemSetPadding(di, 2, 2, 2, 2);
DialogItemSetFill(di, 1, 0);
DialogItemSetAlign(di, 1024, 512);
DialogItemSetText(di, ewin->icccm.wm_role);
}
if (ewin->icccm.wm_command) if (ewin->icccm.wm_command)
{ {
di = DialogAddItem(table, DITEM_TEXT); di = DialogAddItem(table, DITEM_TEXT);
@ -718,7 +838,6 @@ SnapshotEwinDialog(EWin * ewin)
DialogItemSetPadding(di, 2, 2, 2, 2); DialogItemSetPadding(di, 2, 2, 2, 2);
DialogItemSetFill(di, 1, 0); DialogItemSetFill(di, 1, 0);
DialogItemSetText(di, _("Track Changes")); DialogItemSetText(di, _("Track Changes"));
DialogItemCheckButtonSetState(di, sd->track_changes);
DialogItemCheckButtonSetPtr(di, &sd->track_changes); DialogItemCheckButtonSetPtr(di, &sd->track_changes);
di = DialogAddItem(table, DITEM_CHECKBUTTON); di = DialogAddItem(table, DITEM_CHECKBUTTON);
@ -726,7 +845,6 @@ SnapshotEwinDialog(EWin * ewin)
DialogItemSetPadding(di, 2, 2, 2, 2); DialogItemSetPadding(di, 2, 2, 2, 2);
DialogItemSetFill(di, 1, 0); DialogItemSetFill(di, 1, 0);
DialogItemSetText(di, _("Location")); DialogItemSetText(di, _("Location"));
DialogItemCheckButtonSetState(di, sd->snap_location);
DialogItemCheckButtonSetPtr(di, &sd->snap_location); DialogItemCheckButtonSetPtr(di, &sd->snap_location);
di = DialogAddItem(table, DITEM_CHECKBUTTON); di = DialogAddItem(table, DITEM_CHECKBUTTON);
@ -734,7 +852,6 @@ SnapshotEwinDialog(EWin * ewin)
DialogItemSetPadding(di, 2, 2, 2, 2); DialogItemSetPadding(di, 2, 2, 2, 2);
DialogItemSetFill(di, 1, 0); DialogItemSetFill(di, 1, 0);
DialogItemSetText(di, _("Border style")); DialogItemSetText(di, _("Border style"));
DialogItemCheckButtonSetState(di, sd->snap_border);
DialogItemCheckButtonSetPtr(di, &sd->snap_border); DialogItemCheckButtonSetPtr(di, &sd->snap_border);
di = DialogAddItem(table, DITEM_CHECKBUTTON); di = DialogAddItem(table, DITEM_CHECKBUTTON);
@ -742,7 +859,6 @@ SnapshotEwinDialog(EWin * ewin)
DialogItemSetPadding(di, 2, 2, 2, 2); DialogItemSetPadding(di, 2, 2, 2, 2);
DialogItemSetFill(di, 1, 0); DialogItemSetFill(di, 1, 0);
DialogItemSetText(di, _("Size")); DialogItemSetText(di, _("Size"));
DialogItemCheckButtonSetState(di, sd->snap_size);
DialogItemCheckButtonSetPtr(di, &sd->snap_size); DialogItemCheckButtonSetPtr(di, &sd->snap_size);
di = DialogAddItem(table, DITEM_CHECKBUTTON); di = DialogAddItem(table, DITEM_CHECKBUTTON);
@ -750,7 +866,6 @@ SnapshotEwinDialog(EWin * ewin)
DialogItemSetPadding(di, 2, 2, 2, 2); DialogItemSetPadding(di, 2, 2, 2, 2);
DialogItemSetFill(di, 1, 0); DialogItemSetFill(di, 1, 0);
DialogItemSetText(di, _("Desktop")); DialogItemSetText(di, _("Desktop"));
DialogItemCheckButtonSetState(di, sd->snap_desktop);
DialogItemCheckButtonSetPtr(di, &sd->snap_desktop); DialogItemCheckButtonSetPtr(di, &sd->snap_desktop);
di = DialogAddItem(table, DITEM_CHECKBUTTON); di = DialogAddItem(table, DITEM_CHECKBUTTON);
@ -758,7 +873,6 @@ SnapshotEwinDialog(EWin * ewin)
DialogItemSetPadding(di, 2, 2, 2, 2); DialogItemSetPadding(di, 2, 2, 2, 2);
DialogItemSetFill(di, 1, 0); DialogItemSetFill(di, 1, 0);
DialogItemSetText(di, _("Shaded state")); DialogItemSetText(di, _("Shaded state"));
DialogItemCheckButtonSetState(di, sd->snap_shaded);
DialogItemCheckButtonSetPtr(di, &sd->snap_shaded); DialogItemCheckButtonSetPtr(di, &sd->snap_shaded);
di = DialogAddItem(table, DITEM_CHECKBUTTON); di = DialogAddItem(table, DITEM_CHECKBUTTON);
@ -766,7 +880,6 @@ SnapshotEwinDialog(EWin * ewin)
DialogItemSetPadding(di, 2, 2, 2, 2); DialogItemSetPadding(di, 2, 2, 2, 2);
DialogItemSetFill(di, 1, 0); DialogItemSetFill(di, 1, 0);
DialogItemSetText(di, _("Sticky state")); DialogItemSetText(di, _("Sticky state"));
DialogItemCheckButtonSetState(di, sd->snap_sticky);
DialogItemCheckButtonSetPtr(di, &sd->snap_sticky); DialogItemCheckButtonSetPtr(di, &sd->snap_sticky);
di = DialogAddItem(table, DITEM_CHECKBUTTON); di = DialogAddItem(table, DITEM_CHECKBUTTON);
@ -774,7 +887,6 @@ SnapshotEwinDialog(EWin * ewin)
DialogItemSetPadding(di, 2, 2, 2, 2); DialogItemSetPadding(di, 2, 2, 2, 2);
DialogItemSetFill(di, 1, 0); DialogItemSetFill(di, 1, 0);
DialogItemSetText(di, _("Stacking layer")); DialogItemSetText(di, _("Stacking layer"));
DialogItemCheckButtonSetState(di, sd->snap_layer);
DialogItemCheckButtonSetPtr(di, &sd->snap_layer); DialogItemCheckButtonSetPtr(di, &sd->snap_layer);
di = DialogAddItem(table, DITEM_CHECKBUTTON); di = DialogAddItem(table, DITEM_CHECKBUTTON);
@ -782,7 +894,6 @@ SnapshotEwinDialog(EWin * ewin)
DialogItemSetPadding(di, 2, 2, 2, 2); DialogItemSetPadding(di, 2, 2, 2, 2);
DialogItemSetFill(di, 1, 0); DialogItemSetFill(di, 1, 0);
DialogItemSetText(di, _("Window List Skip")); DialogItemSetText(di, _("Window List Skip"));
DialogItemCheckButtonSetState(di, sd->snap_skiplists);
DialogItemCheckButtonSetPtr(di, &sd->snap_skiplists); DialogItemCheckButtonSetPtr(di, &sd->snap_skiplists);
#if USE_COMPOSITE #if USE_COMPOSITE
@ -791,7 +902,6 @@ SnapshotEwinDialog(EWin * ewin)
DialogItemSetPadding(di, 2, 2, 2, 2); DialogItemSetPadding(di, 2, 2, 2, 2);
DialogItemSetFill(di, 1, 0); DialogItemSetFill(di, 1, 0);
DialogItemSetText(di, _("Opacity")); DialogItemSetText(di, _("Opacity"));
DialogItemCheckButtonSetState(di, sd->snap_opacity);
DialogItemCheckButtonSetPtr(di, &sd->snap_opacity); DialogItemCheckButtonSetPtr(di, &sd->snap_opacity);
di = DialogAddItem(table, DITEM_CHECKBUTTON); di = DialogAddItem(table, DITEM_CHECKBUTTON);
@ -799,7 +909,6 @@ SnapshotEwinDialog(EWin * ewin)
DialogItemSetPadding(di, 2, 2, 2, 2); DialogItemSetPadding(di, 2, 2, 2, 2);
DialogItemSetFill(di, 1, 0); DialogItemSetFill(di, 1, 0);
DialogItemSetText(di, _("Shadowing")); DialogItemSetText(di, _("Shadowing"));
DialogItemCheckButtonSetState(di, sd->snap_shadow);
DialogItemCheckButtonSetPtr(di, &sd->snap_shadow); DialogItemCheckButtonSetPtr(di, &sd->snap_shadow);
#endif #endif
@ -809,7 +918,6 @@ SnapshotEwinDialog(EWin * ewin)
DialogItemSetPadding(di, 2, 2, 2, 2); DialogItemSetPadding(di, 2, 2, 2, 2);
DialogItemSetFill(di, 1, 0); DialogItemSetFill(di, 1, 0);
DialogItemSetText(di, _("Never Focus")); DialogItemSetText(di, _("Never Focus"));
DialogItemCheckButtonSetState(di, sd->snap_neverfocus);
DialogItemCheckButtonSetPtr(di, &sd->snap_neverfocus); DialogItemCheckButtonSetPtr(di, &sd->snap_neverfocus);
#endif #endif
if (ewin->icccm.wm_command) if (ewin->icccm.wm_command)
@ -828,7 +936,6 @@ SnapshotEwinDialog(EWin * ewin)
DialogItemSetPadding(di, 2, 2, 2, 2); DialogItemSetPadding(di, 2, 2, 2, 2);
DialogItemSetFill(di, 1, 0); DialogItemSetFill(di, 1, 0);
DialogItemSetText(di, _("Restart application on login")); DialogItemSetText(di, _("Restart application on login"));
DialogItemCheckButtonSetState(di, sd->snap_cmd);
DialogItemCheckButtonSetPtr(di, &sd->snap_cmd); DialogItemCheckButtonSetPtr(di, &sd->snap_cmd);
} }
else else
@ -850,7 +957,6 @@ SnapshotEwinDialog(EWin * ewin)
DialogItemSetPadding(di, 2, 2, 2, 2); DialogItemSetPadding(di, 2, 2, 2, 2);
DialogItemSetFill(di, 1, 0); DialogItemSetFill(di, 1, 0);
DialogItemSetText(di, _("Remember this window's group(s)")); DialogItemSetText(di, _("Remember this window's group(s)"));
DialogItemCheckButtonSetState(di, sd->snap_group);
DialogItemCheckButtonSetPtr(di, &sd->snap_group); DialogItemCheckButtonSetPtr(di, &sd->snap_group);
} }
@ -907,18 +1013,6 @@ CB_ApplyRemember(Dialog * d __UNUSED__, int val, void *data __UNUSED__)
} }
} }
static void
CB_ApplyRememberEscape(Dialog * d, int val __UNUSED__, void *data __UNUSED__)
{
DialogClose(d);
if (rd_ewin_list)
{
Efree(rd_ewin_list);
rd_ewin_list = NULL;
}
}
static void static void
CB_RememberWindowSettings(Dialog * d __UNUSED__, int val __UNUSED__, void *data) CB_RememberWindowSettings(Dialog * d __UNUSED__, int val __UNUSED__, void *data)
{ {
@ -1017,7 +1111,6 @@ SettingsRemember(void)
s = buf; s = buf;
} }
DialogItemSetText(di, s); DialogItemSetText(di, s);
DialogItemCheckButtonSetState(di, rd_ewin_list[i].remove);
DialogItemCheckButtonSetPtr(di, &(rd_ewin_list[i].remove)); DialogItemCheckButtonSetPtr(di, &(rd_ewin_list[i].remove));
if (sn->used) if (sn->used)
@ -1063,7 +1156,7 @@ SettingsRemember(void)
DialogAddButton(d, _("OK"), CB_ApplyRemember, 1, DIALOG_BUTTON_OK); DialogAddButton(d, _("OK"), CB_ApplyRemember, 1, DIALOG_BUTTON_OK);
DialogAddButton(d, _("Close"), CB_ApplyRemember, 1, DIALOG_BUTTON_CLOSE); DialogAddButton(d, _("Close"), CB_ApplyRemember, 1, DIALOG_BUTTON_CLOSE);
DialogSetExitFunction(d, CB_ApplyRemember, 2); DialogSetExitFunction(d, CB_ApplyRemember, 2);
DialogBindKey(d, "Escape", CB_ApplyRememberEscape, 0); DialogBindKey(d, "Escape", DialogCallbackClose, 0);
DialogBindKey(d, "Return", CB_ApplyRemember, 0); DialogBindKey(d, "Return", CB_ApplyRemember, 0);
ShowDialog(d); ShowDialog(d);
@ -1101,12 +1194,14 @@ Real_SaveSnapInfo(int dumval __UNUSED__, void *dumdat __UNUSED__)
{ {
sn = lst[i]; sn = lst[i];
fprintf(f, "NEW: %s\n", sn->name); fprintf(f, "NEW: %s\n", sn->name);
if (sn->win_title) if ((sn->match_flags & SNAP_MATCH_TITLE) && sn->win_title)
fprintf(f, "TITLE: %s\n", sn->win_title); fprintf(f, "TITLE: %s\n", sn->win_title);
if (sn->win_name) if ((sn->match_flags & SNAP_MATCH_NAME) && sn->win_name)
fprintf(f, "NAME: %s\n", sn->win_name); fprintf(f, "NAME: %s\n", sn->win_name);
if (sn->win_class) if ((sn->match_flags & SNAP_MATCH_CLASS) && sn->win_class)
fprintf(f, "CLASS: %s\n", sn->win_class); fprintf(f, "CLASS: %s\n", sn->win_class);
if ((sn->match_flags & SNAP_MATCH_ROLE) && sn->win_role)
fprintf(f, "ROLE: %s\n", sn->win_role);
if (sn->track_changes) if (sn->track_changes)
fprintf(f, "AUTO: yes\n"); fprintf(f, "AUTO: yes\n");
if ((sn->use_flags & SNAP_USE_BORDER) && sn->border_name) if ((sn->use_flags & SNAP_USE_BORDER) && sn->border_name)
@ -1177,7 +1272,8 @@ SpawnSnappedCmds(void)
for (i = 0; i < num; i++) for (i = 0; i < num; i++)
{ {
sn = lst[i]; sn = lst[i];
if ((sn->use_flags & SNAP_USE_COMMAND) && (sn->cmd) && !sn->used) if ((sn->use_flags & SNAP_USE_COMMAND) && (sn->cmd) &&
!sn->used && !(sn->match_flags & SNAP_MATCH_MULTIPLE))
EspawnCmd(sn->cmd); EspawnCmd(sn->cmd);
} }
Efree(lst); Efree(lst);
@ -1214,11 +1310,25 @@ LoadSnapInfo(void)
else if (sn) else if (sn)
{ {
if (!strcmp(s, "TITLE:")) if (!strcmp(s, "TITLE:"))
sn->win_title = Estrdup(atword(buf, 2)); {
sn->win_title = Estrdup(atword(buf, 2));
sn->match_flags |= SNAP_MATCH_TITLE;
}
else if (!strcmp(s, "NAME:")) else if (!strcmp(s, "NAME:"))
sn->win_name = Estrdup(atword(buf, 2)); {
sn->win_name = Estrdup(atword(buf, 2));
sn->match_flags |= SNAP_MATCH_NAME;
}
else if (!strcmp(s, "CLASS:")) else if (!strcmp(s, "CLASS:"))
sn->win_class = Estrdup(atword(buf, 2)); {
sn->win_class = Estrdup(atword(buf, 2));
sn->match_flags |= SNAP_MATCH_CLASS;
}
else if (!strcmp(s, "ROLE:"))
{
sn->win_role = Estrdup(atword(buf, 2));
sn->match_flags |= SNAP_MATCH_ROLE;
}
else if (!strcmp(s, "AUTO:")) else if (!strcmp(s, "AUTO:"))
sn->track_changes = 1; sn->track_changes = 1;
else if (!strcmp(s, "BORDER:")) else if (!strcmp(s, "BORDER:"))
@ -1369,7 +1479,7 @@ LoadSnapInfo(void)
/* make a client window conform to snapshot info */ /* make a client window conform to snapshot info */
void void
SnapshotEwinMatch(EWin * ewin) SnapshotsApplyToEwin(EWin * ewin)
{ {
Snapshot *sn; Snapshot *sn;
int i, ax, ay; int i, ax, ay;
@ -1378,12 +1488,11 @@ SnapshotEwinMatch(EWin * ewin)
if (!sn) if (!sn)
{ {
if (ewin->props.autosave) if (ewin->props.autosave)
SnapshotEwinSet(ewin, SNAP_USE_ALL | SNAP_AUTO); SnapshotEwinSet(ewin, SNAP_MATCH_DEFAULT, SNAP_USE_ALL | SNAP_AUTO);
return; return;
} }
ewin->snap = sn; ewin->snap = sn;
ListChangeItemID(LIST_TYPE_SNAPSHOT, ewin->snap, 1);
if (ewin->props.autosave) if (ewin->props.autosave)
sn->track_changes = 1; sn->track_changes = 1;
@ -1485,16 +1594,17 @@ SnapshotEwinUnmatch(EWin * ewin)
ewin->snap = NULL; ewin->snap = NULL;
sn->used = NULL; sn->used = NULL;
ListChangeItemID(LIST_TYPE_SNAPSHOT, sn, 0);
} }
void void
SnapshotEwinParse(EWin * ewin, const char *params) SnapshotEwinParse(EWin * ewin, const char *params)
{ {
char param[FILEPATH_LEN_MAX]; char param[FILEPATH_LEN_MAX];
unsigned int use_flags; unsigned int match_flags, use_flags;
match_flags = SNAP_MATCH_DEFAULT;
use_flags = 0; use_flags = 0;
for (; params;) for (; params;)
{ {
param[0] = 0; param[0] = 0;
@ -1542,8 +1652,12 @@ SnapshotEwinParse(EWin * ewin, const char *params)
} }
if (ewin->snap) if (ewin->snap)
use_flags |= ewin->snap->use_flags; {
SnapshotEwinSet(ewin, use_flags); match_flags = ewin->snap->match_flags;
use_flags |= ewin->snap->use_flags;
}
SnapshotEwinSet(ewin, match_flags, use_flags);
SaveSnapInfo(); SaveSnapInfo();
} }
@ -1566,7 +1680,7 @@ SnapIpcFunc(const char *params, Client * c __UNUSED__)
Snapshot **lst, *sn; Snapshot **lst, *sn;
int i, num, full; int i, num, full;
char param[FILEPATH_LEN_MAX]; char param[FILEPATH_LEN_MAX];
const char *name, nstr[] = "null"; const char *name;
lst = (Snapshot **) ListItemType(&num, LIST_TYPE_SNAPSHOT); lst = (Snapshot **) ListItemType(&num, LIST_TYPE_SNAPSHOT);
if (!lst) if (!lst)
@ -1601,16 +1715,23 @@ SnapIpcFunc(const char *params, Client * c __UNUSED__)
continue; continue;
} }
IpcPrintf(" Name: %s %s\n" #define SU(sn, item) ((sn->match_flags & item) ? '>' : ':')
" Window Title: %s\n" IpcPrintf(" Snapshot Name: %s %s\n",
" Window Name: %s\n" name, (sn->used) ? "" : "*** Unused ***");
" Window Class: %s\n", if (sn->win_title)
name, (sn->used) ? "" : "*** Unused ***", IpcPrintf(" Window Title%c %s\n", SU(sn, SNAP_MATCH_TITLE),
sn->win_title ? sn->win_title : nstr, sn->win_title);
sn->win_name ? sn->win_name : nstr, if (sn->win_name)
sn->win_class ? sn->win_class : nstr); IpcPrintf(" Window Name%c %s\n", SU(sn, SNAP_MATCH_NAME),
sn->win_name);
if (sn->win_class)
IpcPrintf(" Window Class%c %s\n", SU(sn, SNAP_MATCH_CLASS),
sn->win_class);
if (sn->win_role)
IpcPrintf(" Window Role%c %s\n", SU(sn, SNAP_MATCH_ROLE),
sn->win_role);
if (sn->use_flags & SNAP_AUTO) if (sn->track_changes)
IpcPrintf(" Tracking changes\n"); IpcPrintf(" Tracking changes\n");
if (sn->use_flags & SNAP_USE_BORDER) if (sn->use_flags & SNAP_USE_BORDER)
IpcPrintf(" Border Name: %s\n", SS(sn->border_name)); IpcPrintf(" Border Name: %s\n", SS(sn->border_name));

View File

@ -23,6 +23,17 @@
#ifndef _SNAPS_H_ #ifndef _SNAPS_H_
#define _SNAPS_H_ #define _SNAPS_H_
typedef struct _snapshot Snapshot;
#define SNAP_MATCH_TITLE (1 << 0)
#define SNAP_MATCH_NAME (1 << 1)
#define SNAP_MATCH_CLASS (1 << 2)
#define SNAP_MATCH_ROLE (1 << 3)
#define SNAP_MATCH_ROLE (1 << 3)
#define SNAP_MATCH_MULTIPLE (1 << 8)
#define SNAP_MATCH_DEFAULT (SNAP_MATCH_NAME | SNAP_MATCH_CLASS | SNAP_MATCH_ROLE)
#define SNAP_AUTO (1 << 0) #define SNAP_AUTO (1 << 0)
#define SNAP_USE_BORDER (1 << 1) #define SNAP_USE_BORDER (1 << 1)
#define SNAP_USE_COMMAND (1 << 2) #define SNAP_USE_COMMAND (1 << 2)
@ -40,4 +51,16 @@
#define SNAP_USE_ALL (~1) #define SNAP_USE_ALL (~1)
void Real_SaveSnapInfo(int dumval, void *dumdat);
void LoadSnapInfo(void);
void SaveSnapInfo(void);
void SpawnSnappedCmds(void);
void SnapshotEwinUnmatch(EWin * ewin);
void SnapshotEwinUpdate(EWin * ewin, unsigned int flags);
void SnapshotEwinParse(EWin * ewin, const char *params);
void SnapshotsApplyToEwin(EWin * ewin);
void SettingsRemember(void);
extern const char SnapIpcText[];
void SnapIpcFunc(const char *params, Client * c);
#endif /* _SNAPS_H_ */ #endif /* _SNAPS_H_ */