panel.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /* SLiM - Simple Login Manager
  2. Copyright (C) 1997, 1998 Per Liden
  3. Copyright (C) 2004-06 Simone Rota <sip@varlock.com>
  4. Copyright (C) 2004-06 Johannes Winkelmann <jw@tks6.net>
  5. Copyright (C) 2013 Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. */
  11. #ifndef _PANEL_H_
  12. #define _PANEL_H_
  13. #include <X11/Xlib.h>
  14. #include <X11/keysym.h>
  15. #include <X11/Xft/Xft.h>
  16. #include <X11/cursorfont.h>
  17. #include <X11/Xmu/WinUtil.h>
  18. #include <sys/wait.h>
  19. #include <stdlib.h>
  20. #include <signal.h>
  21. #include <iostream>
  22. #include <string>
  23. #ifdef NEEDS_BASENAME
  24. #include <libgen.h>
  25. #endif
  26. #include "switchuser.h"
  27. #include "log.h"
  28. #include "image.h"
  29. struct Rectangle {
  30. int x;
  31. int y;
  32. unsigned int width;
  33. unsigned int height;
  34. Rectangle() : x(0), y(0), width(0), height(0) {};
  35. Rectangle(int x, int y, unsigned int width,
  36. unsigned int height) :
  37. x(x), y(y), width(width), height(height) {};
  38. bool is_empty() const {
  39. return width == 0 || height == 0;
  40. }
  41. };
  42. class Panel {
  43. public:
  44. enum ActionType {
  45. Login,
  46. Lock,
  47. Console,
  48. Reboot,
  49. Halt,
  50. Exit,
  51. Suspend
  52. };
  53. enum FieldType {
  54. Get_Name,
  55. Get_Passwd
  56. };
  57. enum PanelType {
  58. Mode_DM,
  59. Mode_Lock
  60. };
  61. Panel(Display *dpy, int scr, Window root, Cfg *config,
  62. const std::string& themed, PanelType panel_mode);
  63. ~Panel();
  64. void OpenPanel();
  65. void ClosePanel();
  66. void ClearPanel();
  67. void WrongPassword(int timeout);
  68. void Message(const std::string &text);
  69. void Error(const std::string &text);
  70. void EventHandler(const FieldType &curfield);
  71. std::string getSession();
  72. ActionType getAction(void) const;
  73. void Reset(void);
  74. void ResetName(void);
  75. void ResetPasswd(void);
  76. void SetName(const std::string &name);
  77. const std::string& GetName(void) const;
  78. const std::string& GetPasswd(void) const;
  79. void SwitchSession();
  80. private:
  81. Panel();
  82. void Cursor(int visible);
  83. unsigned long GetColor(const char *colorname);
  84. void OnExpose(void);
  85. bool OnKeyPress(XEvent& event);
  86. void ShowText();
  87. void ShowSession();
  88. void SlimDrawString8(XftDraw *d, XftColor *color, XftFont *font,
  89. int x, int y, const std::string &str,
  90. XftColor *shadowColor,
  91. int xOffset, int yOffset);
  92. Rectangle GetPrimaryViewport();
  93. void ApplyBackground(Rectangle = Rectangle());
  94. /* Private data */
  95. PanelType mode; /* work mode */
  96. Cfg *cfg;
  97. Window Win;
  98. Window Root;
  99. Display *Dpy;
  100. int Scr;
  101. int X, Y;
  102. GC TextGC;
  103. GC WinGC;
  104. XftFont *font;
  105. XftColor inputshadowcolor;
  106. XftColor inputcolor;
  107. XftColor msgcolor;
  108. XftColor msgshadowcolor;
  109. XftFont *msgfont;
  110. XftColor introcolor;
  111. XftFont *introfont;
  112. XftFont *welcomefont;
  113. XftColor welcomecolor;
  114. XftFont *sessionfont;
  115. XftColor sessioncolor;
  116. XftColor sessionshadowcolor;
  117. XftColor welcomeshadowcolor;
  118. XftFont *enterfont;
  119. XftColor entercolor;
  120. XftColor entershadowcolor;
  121. ActionType action;
  122. FieldType field;
  123. //Pixmap background;
  124. /* Username/Password */
  125. std::string NameBuffer;
  126. std::string PasswdBuffer;
  127. std::string HiddenPasswdBuffer;
  128. /* screen stuff */
  129. Rectangle viewport;
  130. /* Configuration */
  131. int input_name_x;
  132. int input_name_y;
  133. int input_pass_x;
  134. int input_pass_y;
  135. int inputShadowXOffset;
  136. int inputShadowYOffset;
  137. int input_cursor_height;
  138. int welcome_x;
  139. int welcome_y;
  140. int welcome_shadow_xoffset;
  141. int welcome_shadow_yoffset;
  142. int session_shadow_xoffset;
  143. int session_shadow_yoffset;
  144. int intro_x;
  145. int intro_y;
  146. int username_x;
  147. int username_y;
  148. int username_shadow_xoffset;
  149. int username_shadow_yoffset;
  150. int password_x;
  151. int password_y;
  152. std::string welcome_message;
  153. std::string intro_message;
  154. /* Pixmap data */
  155. Pixmap PanelPixmap;
  156. Image *image;
  157. /* For thesting themes */
  158. bool testing;
  159. std::string themedir;
  160. /* Session handling */
  161. std::string session_name;
  162. std::string session_exec;
  163. };
  164. #endif /* _PANEL_H_ */