You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

189 lines
3.9 KiB

  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. void EraseLastChar(string &formerString);
  86. bool OnKeyPress(XEvent& event);
  87. void ShowText();
  88. void ShowSession();
  89. void SlimDrawString8(XftDraw *d, XftColor *color, XftFont *font,
  90. int x, int y, const std::string &str,
  91. XftColor *shadowColor,
  92. int xOffset, int yOffset);
  93. Rectangle GetPrimaryViewport();
  94. void ApplyBackground(Rectangle = Rectangle());
  95. /* Private data */
  96. PanelType mode; /* work mode */
  97. Cfg *cfg;
  98. Window Win;
  99. Window Root;
  100. Display *Dpy;
  101. int Scr;
  102. int X, Y;
  103. GC TextGC;
  104. GC WinGC;
  105. XftFont *font;
  106. XftColor inputshadowcolor;
  107. XftColor inputcolor;
  108. XftColor msgcolor;
  109. XftColor msgshadowcolor;
  110. XftFont *msgfont;
  111. XftColor introcolor;
  112. XftFont *introfont;
  113. XftFont *welcomefont;
  114. XftColor welcomecolor;
  115. XftFont *sessionfont;
  116. XftColor sessioncolor;
  117. XftColor sessionshadowcolor;
  118. XftColor welcomeshadowcolor;
  119. XftFont *enterfont;
  120. XftColor entercolor;
  121. XftColor entershadowcolor;
  122. ActionType action;
  123. FieldType field;
  124. //Pixmap background;
  125. /* Username/Password */
  126. std::string NameBuffer;
  127. std::string PasswdBuffer;
  128. std::string HiddenPasswdBuffer;
  129. /* screen stuff */
  130. Rectangle viewport;
  131. /* Configuration */
  132. int input_name_x;
  133. int input_name_y;
  134. int input_pass_x;
  135. int input_pass_y;
  136. int inputShadowXOffset;
  137. int inputShadowYOffset;
  138. int input_cursor_height;
  139. int welcome_x;
  140. int welcome_y;
  141. int welcome_shadow_xoffset;
  142. int welcome_shadow_yoffset;
  143. int session_shadow_xoffset;
  144. int session_shadow_yoffset;
  145. int intro_x;
  146. int intro_y;
  147. int username_x;
  148. int username_y;
  149. int username_shadow_xoffset;
  150. int username_shadow_yoffset;
  151. int password_x;
  152. int password_y;
  153. std::string welcome_message;
  154. std::string intro_message;
  155. /* Pixmap data */
  156. Pixmap PanelPixmap;
  157. Image *image;
  158. /* For thesting themes */
  159. bool testing;
  160. std::string themedir;
  161. /* Session handling */
  162. std::string session_name;
  163. std::string session_exec;
  164. };
  165. #endif /* _PANEL_H_ */