Browse Source

Replace Rectangle constructors with static methods

Getty Ritter 1 year ago
parent
commit
5994dfa274
2 changed files with 19 additions and 13 deletions
  1. 7 7
      panel.cpp
  2. 12 6
      panel.h

+ 7 - 7
panel.cpp

@@ -428,8 +428,8 @@ void Panel::Cursor(int visible) {
               xx+1, y2);
   } else {
     if (mode == Mode_Lock)
-      ApplyBackground(Rectangle(xx+1, yy-cheight,
-                                1, y2-(yy-cheight)+1));
+      ApplyBackground(Rectangle::mk_rect(xx+1, yy-cheight,
+                                         1, y2-(yy-cheight)+1));
     else
       XClearArea(Dpy, Win, xx+1, yy-cheight,
                  1, y2-(yy-cheight)+1, false);
@@ -661,9 +661,9 @@ bool Panel::OnKeyPress(XEvent& event) {
     int maxLength = extents.width;
 
     if (mode == Mode_Lock)
-      ApplyBackground(Rectangle(input_pass_x - 3,
-                                input_pass_y - maxHeight - 3,
-                                maxLength + 6, maxHeight + 6));
+      ApplyBackground(Rectangle::mk_rect(input_pass_x - 3,
+                                         input_pass_y - maxHeight - 3,
+                                         maxLength + 6, maxHeight + 6));
     else
       XClearArea(Dpy, Win, xx - 3, yy-maxHeight - 3,
                  maxLength + 6, maxHeight + 6, false);
@@ -859,8 +859,8 @@ const string& Panel::GetPasswd(void) const{
 }
 
 Rectangle Panel::GetPrimaryViewport() {
-  Rectangle fallback;
-  Rectangle result;
+  Rectangle fallback = Rectangle::empty();
+  Rectangle result = Rectangle::empty();
 
   RROutput primary;
   XRROutputInfo *primary_info;

+ 12 - 6
panel.h

@@ -37,11 +37,17 @@ struct Rectangle {
   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) :
+private:
+  Rectangle(int x, int y, unsigned int width, unsigned int height) :
     x(x), y(y), width(width), height(height) {};
+public:
+  static Rectangle empty() {
+    return Rectangle(0, 0, 0, 0);
+  }
+  static Rectangle mk_rect(int x, int y, unsigned int width, unsigned int height) {
+    return Rectangle(x, y, width, height);
+  }
+
   bool is_empty() const {
     return width == 0 || height == 0;
   }
@@ -105,7 +111,7 @@ private:
                        int xOffset, int yOffset);
 
   Rectangle GetPrimaryViewport();
-  void ApplyBackground(Rectangle = Rectangle());
+  void ApplyBackground(Rectangle = Rectangle::empty());
 
   /* Private data */
   PanelType mode; /* work mode */
@@ -144,7 +150,7 @@ private:
   std::string HiddenPasswdBuffer;
 
   /* screen stuff */
-  Rectangle viewport;
+  Rectangle viewport = Rectangle::empty();
 
   /* Configuration */
   int input_name_x;