Tidyup
[pager.git] / pager.c
diff --git a/pager.c b/pager.c
index 85dfd5f..d7818ef 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -1,9 +1,7 @@
 /* gcc -o pager pager.c -lX11 -lXmu -ldockapp */
-#if 0
-#include <X11/extensions/Xrender.h>
-#endif
 #include <X11/Xatom.h>
 #include <dockapp.h>
+#include <string.h>
 
 #define DOCKAPP_SIZE 56
 #define SPEED 100
@@ -18,8 +16,8 @@ static long desktop = -1;
 static Window drag_window;
 static int drag_x, drag_y;
 static int drag_button;
-static int dockapp_x, dockapp_y, dockapp_width, dockapp_height;
-static unsigned int dockapp_border, dockapp_depth;
+static int dockapp_x, dockapp_y;
+static unsigned int dockapp_width, dockapp_height, dockapp_border, dockapp_depth;
 static double scale;
 
 static int desktop_geometry_supported;
@@ -34,7 +32,6 @@ typedef struct {
 
 int error_handler(Display *display, XErrorEvent *event) {
   char buffer[512];
-  int length;
 
   switch (event->error_code) {
     case BadWindow:
@@ -259,20 +256,10 @@ void change(int button, int state, int x, int y) {
     if (! clients[i]->window) continue;
     if (! clicked(&clients[i]->rect, x, y)) continue;
 
-    if (button == 4) {
-      client_message(client_state_atom, clients[i]->window, 0, above_state, 0, 0, 0);
-      client_message(client_state_atom, clients[i]->window, 1, below_state, 0, 0, 0);
-    }
-    else if (button == 5) {
-      client_message(client_state_atom, clients[i]->window, 0, below_state, 0, 0, 0);
-      client_message(client_state_atom, clients[i]->window, 1, above_state, 0, 0, 0);
-    }
-    else {
-      drag_window = clients[i]->window;
-      drag_button = button;
-      drag_x = x - clients[i]->rect.x;
-      drag_y = y - clients[i]->rect.y;
-    }
+    drag_window = (Window) clients[i]->window;
+    drag_button = button;
+    drag_x = x - clients[i]->rect.x;
+    drag_y = y - clients[i]->rect.y;
     break;
   }
   destroy_clients(&clients, num_clients);
@@ -289,35 +276,12 @@ void release(int button, int state, int x, int y) {
   if (button == drag_button) drag_window = 0;
 }
 
-void move(int x, int y) {
-  long dest_x, dest_y;
-
-  if (! drag_window) return;
-  if (x < 0 || y < 0) return;
-  if (x >= dockapp_width || y >= dockapp_height) return;
-
-  dest_x = (long) ((double) (x - drag_x) * scale);
-  dest_y = (long) ((double) (y - drag_y) * scale);
-
-  if (moveresize_supported) {
-    client_message(moveresize_window_atom, drag_window, StaticGravity | (3 << 8) | (FromTool << 12), drag_x, drag_y, 0, 0);
-  }
-  else {
-    XMoveWindow(DADisplay, drag_window, dest_x, dest_y);
-  }
-
-  page();
-}
-
 void page() {
-  Window child, active_window;
-  XWindowAttributes attr;
+  Window active_window;
   Pixmap pixmap;
-  DARect rect;
-  long i, j;
+  long i;
   unsigned long num_clients;
-  long client_desktop, active_desktop;
-  int active;
+  unsigned long active_desktop;
   GC gc;
   client_t **clients;
 
@@ -343,32 +307,12 @@ void page() {
 
     /* Draw small windows. */
     if (clients[i]->rect.width < 2 || clients[i]->rect.height < 2) gc = window_border1GC;
-    else if (clients[i]->window == active_window) gc = active_windowGC;
+    else if ((long) clients[i]->window == active_window) gc = active_windowGC;
     else gc = inactive_windowGC;
 
     XFillRectangle(DADisplay, pixmap, gc, clients[i]->rect.x, clients[i]->rect.y, clients[i]->rect.width, clients[i]->rect.height);
     if (clients[i]->rect.width < 2 || clients[i]->rect.height < 2) continue;
 
-    /* Thumbnail. */
-#if 0
-      XRenderPictureAttributes pa;
-      Pixmap client_pixmap = XCreatePixmap(DADisplay, wins[i], width, height, DefaultDepth(DADisplay, DefaultScreen(DADisplay)));
-      //XCopyArea(DADisplay, wins[i], client_pixmap, DefaultGC(DADisplay, DefaultScreen(DADisplay)), 0, 0, width, height, 0, 0);
-      Picture client_picture = XRenderCreatePicture(DADisplay, client_pixmap, XRenderFindVisualFormat(DADisplay, attr.visual), CPSubwindowMode, &pa);
-
-      XTransform xform = {{
-        { XDoubleToFixed(1.0), 0, 0 },
-        { 0, XDoubleToFixed(1.0), 0 },
-        { 0, 0, XDoubleToFixed(scale) },
-      }};
-
-      XRenderSetPictureFilter(DADisplay, client_picture, FilterBilinear, 0, 0);
-      XRenderSetPictureTransform(DADisplay, client_picture, &xform);
-      XRenderComposite(DADisplay, PictOpSrc, client_picture, None, picture, 0, 0, 0, 0, rect.x, rect.y, rect.width, rect.height);
-      XFreePixmap(DADisplay, client_pixmap);
-      XSync(DADisplay, False);
-#endif
-
     XDrawLine(DADisplay, pixmap, window_border1GC, clients[i]->rect.x, clients[i]->rect.y, clients[i]->rect.x, clients[i]->rect.y + clients[i]->rect.height - 2);
     XDrawLine(DADisplay, pixmap, window_border1GC, clients[i]->rect.x + 1, clients[i]->rect.y, clients[i]->rect.x + clients[i]->rect.width - 1, clients[i]->rect.y);
     XDrawLine(DADisplay, pixmap, window_border2GC, clients[i]->rect.x, clients[i]->rect.y + clients[i]->rect.height - 1, clients[i]->rect.x + clients[i]->rect.width - 1, clients[i]->rect.y + clients[i]->rect.height - 1);
@@ -381,6 +325,26 @@ void page() {
   XFreePixmap(DADisplay, pixmap);
 }
 
+void move(int x, int y) {
+  long dest_x, dest_y;
+
+  if (! drag_window) return;
+  if (x < 0 || y < 0) return;
+  if (x >= dockapp_width || y >= dockapp_height) return;
+
+  dest_x = (long) ((double) (x - drag_x) * scale);
+  dest_y = (long) ((double) (y - drag_y) * scale);
+
+  if (moveresize_supported) {
+    client_message(moveresize_window_atom, drag_window, StaticGravity | (3 << 8) | (FromTool << 12), drag_x, drag_y, 0, 0);
+  }
+  else {
+    XMoveWindow(DADisplay, drag_window, dest_x, dest_y);
+  }
+
+  page();
+}
+
 int main(int argc, char **argv) {
   Display *display;
   unsigned int root_width, root_height;
@@ -406,7 +370,7 @@ int main(int argc, char **argv) {
     dockapp_width = (double) DOCKAPP_SIZE / aspect;
   }
 
-  DAParseArguments(argc, argv, &options, 1, "BLURB", "BLORB");
+  DAParseArguments(argc, argv, &options, 1, "OPTIONS", "pager");
   DAOpenDisplay(0, argc, argv);
   DACreateIcon("pager", dockapp_width, dockapp_height, argc, argv);
 
@@ -436,7 +400,7 @@ int main(int argc, char **argv) {
     desktop = get_atom_long(current_desktop_atom, XA_CARDINAL, DefaultRootWindow(DADisplay));
   }
   else if (desktop-- > num_desktops) {
-    fprintf(stderr, "There are only %d desktops!\n", num_desktops);
+    fprintf(stderr, "There are only %ld desktops!\n", num_desktops);
     exit(111);
   }
 
@@ -444,4 +408,6 @@ int main(int argc, char **argv) {
   setup_GCs();
   DAShow();
   DAEventLoop();
+
+  exit(0);
 }