summaryrefslogtreecommitdiff
path: root/src/session.h
blob: 10d7b55245f1353bff2f2403fddd299bf5792a81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
 *
 * Compiz session plugin
 *
 * session.c
 *
 * Copyright (c) 2008 Travis Watkins <amaranth@ubuntu.com>
 * Copyright (c) 2008 Danny Baumann <maniac@opencompositing.org>
 * Copyright (c) 2006 Patrick Niklaus
 *
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * Authors: Travis Watkins <amaranth@ubuntu.com>
 *          Patrick Niklaus
 **/

#include <core/core.h>
#include <core/pluginclasshandler.h>

#include <X11/Xatom.h>
#include <X11/SM/SM.h>

#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <libxml/xpath.h>

#include <iostream>
#include <fstream>

#include "session_options.h"

typedef struct
{
    CompString clientId;
    CompString title;
    CompString resName;
    CompString resClass;
    CompString role;
    CompString command;

    bool     geometrySet;
    CompRect geometry;

    unsigned int state;
    bool         minimized;
    int          workspace;
} SessionItem;

class SessionScreen :
    public ScreenInterface,
    public PluginClassHandler<SessionScreen, CompScreen>,
    public SessionOptions
{
    public:
	SessionScreen (CompScreen *);

	void handleEvent (XEvent *);
	void sessionEvent (CompSession::Event, CompOption::Vector &);

	bool readWindow (CompWindow *);

    private:
	bool getUtf8Property (Window, Atom, CompString&);
	bool getTextProperty (Window, Atom, CompString&);
	bool getWindowTitle (Window, CompString&);
	bool getWindowClass (Window, CompString&, CompString&);
	bool getIsEmbedded (Window);
	bool getClientLeaderProperty (CompWindow *, Atom, CompString&);

	int getIntForProp (xmlNodePtr, const char *);
	CompString getStringForProp (xmlNodePtr, const char *);

	bool isSessionWindow (CompWindow *);
	void writeWindow (CompWindow *);

	void saveState (const CompString &);
	void readState (xmlNodePtr);
	void loadState (const CompString &);

	bool matchWindowClass (CompWindow *, const SessionItem&);

	CompString getFileName (const CompString &);
	bool createDir (const CompString&);
	
	Atom visibleNameAtom;
	Atom clientIdAtom;
	Atom embedInfoAtom;
	Atom roleAtom;
	Atom commandAtom;

	typedef std::list<SessionItem> ItemList;

	ItemList     items;
	std::fstream file;
};

class SessionWindow :
    public WindowInterface,
    public PluginClassHandler<SessionWindow, CompWindow>
{
    public:
	SessionWindow (CompWindow *);

	bool place (CompPoint &);

	CompWindow *window;
	bool       positionSet;
	CompPoint  position;
};

class SessionPluginVTable :
    public CompPlugin::VTableForScreenAndWindow<SessionScreen, SessionWindow>
{
    public:
	bool init ();
};