File: panel.h

package info (click to toggle)
slim 1.4.1-2.2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,780 kB
  • sloc: cpp: 4,383; sh: 202; makefile: 23
file content (181 lines) | stat: -rw-r--r-- 3,902 bytes parent folder | download | duplicates (2)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/* SLiM - Simple Login Manager
   Copyright (C) 1997, 1998 Per Liden
   Copyright (C) 2004-06 Simone Rota <sip@varlock.com>
   Copyright (C) 2004-06 Johannes Winkelmann <jw@tks6.net>
   Copyright (C) 2013 Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
   Copyright (C) 2022-23 Rob Pearce <slim@flitspace.org.uk>

   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.
*/

#ifndef _PANEL_H_
#define _PANEL_H_

#include <X11/Xlib.h>
#include <X11/Xft/Xft.h>
#include <stdlib.h>
#include <string>

#ifdef NEEDS_BASENAME
#include <libgen.h>
#endif


// Forward declarations
class Image;
class Cfg;


struct Rectangle {
	int x;
	int y;
	unsigned int width;
	unsigned int height;

	Rectangle() : x(0), y(0), width(0), height(0) {};
	Rectangle(int x, int y, unsigned int width, unsigned int height)
		: x(x), y(y), width(width), height(height)
	{}

	bool is_empty() const { return width == 0 || height == 0; }
};

class Panel
{
public:
	enum ActionType {
		Login,
		UnLock = Login,     // slimlock doesn't actually care about this
		Console,
		Reboot,
		Halt,
		Exit,
		Suspend
	};

	enum FieldType {
		Get_Name,
		Get_Passwd
	};

	enum PanelType {
		Mode_DM,
		Mode_Test,
		Mode_Lock
	};

	Panel(Display *dpy, int scr, Window root, Cfg *config,
		  const std::string& themed, PanelType panel_mode);
	~Panel();
	void OpenPanel();
	void ClosePanel();
	void WrongPassword(int timeout);
	void Message(const std::string &text);
	void EventHandler(const FieldType &curfield);
	std::string getSession();
	ActionType getAction(void) const;

	void Reset(void);
	void ResetName(void);
	void ResetPasswd(void);
	void SetName(const std::string &name);
	const std::string& GetName(void) const;
	const std::string& GetPasswd(void) const;
	void SwitchSession();

	Atom BackgroundPixmapId;	// from XInternAtom -- does it need to be a member var?
	void setBackground(void);
	void HideCursor();

private:
	Panel();
	void TextCursor(int visible);
	unsigned long GetColor(const char *colorname);
	void OnExpose(void);
	void EraseLastChar(std::string &formerString);
	bool OnKeyPress(XEvent& event);
	void ShowText();
	void ShowSession();

	void SlimDrawString8(XftDraw *d, XftColor *color, XftFont *font,
							int x, int y, const std::string &str,
							XftColor *shadowColor,
							int xOffset, int yOffset);

	Rectangle GetPrimaryViewport();

	/* Private data */
	Cfg *cfg;
	PanelType mode; /* work mode */
	Display *Dpy;
	int Scr;
	Window Win;
	Window Root;
	Window RealRoot;
	int X, Y;
	GC TextGC;
	XftFont *font;
	XftColor inputshadowcolor;
	XftColor inputcolor;
	XftColor msgcolor;
	XftColor msgshadowcolor;
	XftFont *msgfont;
	XftFont *welcomefont;
	XftColor welcomecolor;
	XftFont *sessionfont;
	XftColor sessioncolor;
	XftColor sessionshadowcolor;
	XftColor welcomeshadowcolor;
	XftFont *enterfont;
	XftColor entercolor;
	XftColor entershadowcolor;
	ActionType action;
	FieldType field;
	XGlyphInfo MsgExtents;
	
	/* Username/Password */
	std::string NameBuffer;
	std::string PasswdBuffer;
	std::string HiddenPasswdBuffer;

	/* screen stuff */
	Rectangle viewport;

	/* Configuration */
	int input_name_x;
	int input_name_y;
	int input_pass_x;
	int input_pass_y;
	int inputShadowXOffset;
	int inputShadowYOffset;
	int welcome_x;
	int welcome_y;
	int welcome_shadow_xoffset;
	int welcome_shadow_yoffset;
	int session_shadow_xoffset;
	int session_shadow_yoffset;
	int username_x;
	int username_y;
	int username_shadow_xoffset;
	int username_shadow_yoffset;
	int password_x;
	int password_y;
	std::string welcome_message;

	/* Pixmap data */
	Pixmap PanelPixmap;

	Image *image;
	Image *bgImg;

	std::string themedir;

	/* Session handling */
	std::string session_name;
    std::string session_exec;
};

#endif /* _PANEL_H_ */