You are not logged in.

#26 2009-04-29 12:11:29

Wra!th
Member
Registered: 2009-03-31
Posts: 342

Re: Bare Window Manager (ex-MMWM)

2 important changes today:
1 - added a status feature and binding that gets output from a command defined in conf.h, and pops it on-screen using the built-in message() function.
For now it's doesn't parse newlines (so only first line in output is shown), and it's limited at 256 chars (temporary!), but working on making it multiline as I type smile
2 - cursor options (default and the one used when switching to command mode). Needs cursors found in X11/cursorfont.h which are enough.

tMWxqOQ
Status at work

# Maintainer: Wra!th <wraith@archlinux.us>

pkgname=barewm-git
pkgver=0.1
pkgrel=1
pkgdesc="A minimal fullscreen window manager."
arch=('i686' 'x86_64')
url="http://github.com/wraith0x2b/barewm/"
license=('GPL')
depends=('libx11')
makedepends=('git')
provides=(barewm)
source=()
md5sums=()

_gitroot="git://github.com/wraith0x2b/barewm.git"
_gitname="barewm"

build() {
  cd $srcdir

 ## Git checkout
  if [ -d $srcdir/${_gitname} ] ; then
    msg "Git checkout:  Updating existing tree"
    cd ${_gitname} && git pull origin  || return 1
    msg "Git checkout:  Tree has been updated"
  else
    msg "Git checkout:  Retrieving sources"
    git clone ${_gitroot}  || return 1
  fi
  msg "Checkout completed"

 ## Build
  rm -rf $srcdir/${_gitname}-build
  cp -r $srcdir/${_gitname} $srcdir/${_gitname}-build  || return 1
  cd $srcdir/${_gitname}-build
  
  make  || return 1
}

I am trying to get an AUR package for this, and this is the pkgbuild I managed to create. It gets stuff from github, it leaves me with a .tar.gz, but I need it to install it too. I tried pacman -U <pkg>.tar.gz, but no binary gets created. Help! smile
I suck at PKGBUILDs so please help.

edit: actually I extracted the resulting tar.gz and it's just a folder, no binary no nothing

Last edited by Wra!th (2009-04-29 13:11:50)


MacGregor DESPITE THEM!
7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00

Offline

#27 2009-04-29 14:36:22

dimigon
Member
Registered: 2009-03-07
Posts: 139
Website

Re: Bare Window Manager (ex-MMWM)

Hello, I've written a small patch for your window manager. It is mostly a bit of code cleanup. I've added a signal handler to trap SIGCHLD and wait on the terminated children so we don't have zombies lying around. I've also changed some stuff in the echo_ouput function. I made the next/prev window functions to be cyclic so when you go prev on the first window you reach the last one. I am not sure if you want that but I find it useful. I had no time to check the code thoroughly so please check the patch before applying it. I also suggest that you do not use an array for the windows but rather a double linked list so you can be more dynamic. Consider using a source code formatter so your code stays uniform. While reading through the original code, lines [389, 393] (check the patch) did not make sense because the codepath leads to the same block of code, however since I had no time to check what you wanted to do I made an assumption. Good luck with the project!

--- barewm.c    2009-04-29 15:16:52.000000000 -0700
+++ barewm_modified.c    2009-04-29 15:28:38.000000000 -0700
@@ -7,50 +7,58 @@
 #include <unistd.h>
 #include <errno.h>
 #include <stdlib.h>
+#include <ctype.h>
 #include "conf.h"
+#include <sys/wait.h>
 #include <X11/cursorfont.h>
 
 #define DEBUG 0
 
-Display         * display;
-Window             root;
-Screen             *screen;
-int             SCREEN_WIDTH;
-int             SCREEN_HEIGHT;
-GC             BARE_GC, BARE_SELECTEDFG_GC, BARE_SELECTEDBG_GC;
-Colormap         BARE_colormap = None;
-XFontStruct  * fontstruct;
+#ifdef DEBUG
+#define LOG_DEBUG(...) LOG(__VA_ARGS__)
+#else
+#define LOG_DEBUG(...)
+#endif
+
+static Display         * display;
+static Window             root;
+static Screen             *screen;
+static int                 SCREEN_WIDTH;
+static int             SCREEN_HEIGHT;
+static GC                 BARE_GC, BARE_SELECTEDFG_GC, BARE_SELECTEDBG_GC;
+static Colormap         BARE_colormap = None;
+static XFontStruct  * fontstruct;
 
 #define max_windows 999 
-Window windows_container[max_windows];
-Window selected;
+static Window windows_container[max_windows];
+static Window selected;
 
-void main_loop();
-GC BARE_Colors(char *FG, char *BG);
-void handle_keypress_event(XEvent *e);
-void handle_maprequest_event(XEvent *e);
-void handle_configure_event(XEvent *e);
-void handle_destroy_event(XEvent *e);
-void handle_expose_event(XEvent *e);
-int handle_x_error(Display *display, XErrorEvent *e);
-void handle_property_event(XEvent *e);
-int init_gc();
-void spawn(const char *cmd);
-unsigned long name2color(const char *cid);
-void LOG(const char *text, ...);
-void LOG_DEBUG(const char *text, ...);
-void list_windows();
-int get_free_position();
-int free_position(Window window);
-int get_position(Window window);
-int select_window(int window);
-void grab_keyboard();
-int get_prev_window();
-int get_next_window();
-void message(const char *text, ...);
-void echo_output(char *cmd);
+static void main_loop(void);
+static void handle_keypress_event(XEvent *e);
+static void handle_maprequest_event(XEvent *e);
+static void handle_configure_event(XEvent *e);
+static void handle_destroy_event(XEvent *e);
+static void handle_expose_event(XEvent *e);
+static int handle_x_error(Display *display, XErrorEvent *e);
+static void handle_property_event(XEvent *e);
+static int init_gc(void);
+static void spawn(const char *cmd);
+static unsigned long name2color(const char *cid);
+static void LOG(const char *text, ...);
+static void list_windows(void);
+static int get_free_position(void);
+static int free_position(Window window);
+static int get_position(Window window);
+static int select_window(int window);
+static void grab_keyboard(void);
+static int get_prev_window(void);
+static int get_next_window(void);
+static void message(const char *text, ...);
+static void echo_output(const char *cmd);
+static int TextHeight(const XFontStruct *fs);
+static void get_wlistpos(int *win_x, int *win_y, int win_width, int win_height);
 
-void LOG(const char *text, ...)
+static void LOG(const char *text, ...)
 {
     va_list vl;
     va_start(vl, text);
@@ -58,39 +66,43 @@
     va_end(vl);
 }
 
-void LOG_DEBUG(const char *text, ...)
-{
-    if(DEBUG == 1){
-        va_list vl;
-        va_start(vl, text);
-        vfprintf(stderr, text, vl);
-        va_end(vl);
+static void sighandler(int sig) {
+    pid_t pid;
+    int status, serrno;
+
+    if (sig == SIGCHLD) {
+        serrno = errno;
+        while (1) {
+            pid = waitpid(WAIT_ANY, &status, WNOHANG);
+            if (pid <= 0)
+                break;
+        }
+        errno = serrno;
     }
 }
 
-void spawn(const char *cmd)
-{
-    if(fork() == 0) {
-        if(display) close(ConnectionNumber(display));
-        setsid();
-        execl("/bin/sh", "/bin/sh", "-c", cmd, (char *)NULL);
-    }
+static void spawn(const char *cmd) {
+  if(fork() == 0) {
+    if(display) close(ConnectionNumber(display));
+    setsid();
+    execl("/bin/sh", "/bin/sh", "-c", cmd, (char *)NULL);
+  }
 }
 
-int TextWidth(XFontStruct *fs, const char *text)
+static int TextWidth(XFontStruct *fs, const char *text)
 {
     if(strlen(text) >= 1 && text != NULL) {
         return XTextWidth(fs, text, strlen(text));
-    } else {
-        return 1;
     }
+    
+    return 1;
 }
 
-int TextHeight(XFontStruct *fs) {
+static int TextHeight(const XFontStruct *fs) {
     return fs->ascent + fs->descent;
 }
 
-unsigned long name2color(const char *cid)
+static unsigned long name2color(const char *cid)
 {
     XColor tmpcol;
 
@@ -106,7 +118,7 @@
     return tmpcol.pixel;
 }
 
-int init_gc()
+static int init_gc(void)
 {
     XGCValues gcv;
        gcv.font = fontstruct->fid;
@@ -123,66 +135,69 @@
 
     return 0;
 }
-int get_prev_window()
+
+static int get_prev_window(void)
 {
-    int x;
-    for(x = get_position(selected) - 1; x >= 0; x--)
-    {
-        if(windows_container[x] != None)
-        {
+    int x, y = 0, pos = get_position(selected);
+    
+    x = (pos == -1) ? -1 : pos - 1;
+    do {
+        x = (x < 0) ? max_windows + x : x;
+        if (windows_container[x] != None) {
             LOG_DEBUG("Found previous window at: %d\n", x);
             return x;
         }
-    }
+        --x;
+    } while (++y < max_windows);
 
     return -1;
 }
-int get_next_window()
+
+static int get_next_window(void)
 {
-    int x;
-    for(x = get_position(selected) + 1; x < max_windows; x++)
-    {
-        if(windows_container[x] != None)
-        {
+    int x, y = 0, pos = get_position(selected);
+
+    x = pos + 1;
+    do {
+        x %= max_windows;
+        if (windows_container[x] != None) {
             LOG_DEBUG("Found next window at: %d\n", x);
             return x;
         }
-    }
+        ++x;
+    } while (++y < max_windows);
+
     return -1;
 }
-void grab_keyboard()
+
+static void grab_keyboard(void)
 {
     XGrabKey(display, XKeysymToKeycode (display, KEY_PREFIX), MOD_MASK, root, True, GrabModeAsync, GrabModeAsync);
 }
 
-void echo_output(char *cmd)
+void echo_output(const char *cmd)
 {
-    int ch = 0;
-    int x = 0;
     char s[256] = "";
     FILE *out = popen(cmd, "r");
-    if(out)
-    {
-        while(ch != EOF && ch != '\n' && x < 256) {
-            ch = fgetc(out);
-            s[x] = ch;
-            x++;
+    
+    if (out) {
+        if (fgets(s, sizeof(s), out) != NULL) {
+            if (s[strlen(s) - 1] == '\n')
+                s[strlen(s) - 1] = '\0';
+            message(s);
         }
-        s[x -1] = 0;
         pclose(out);
-        message(s);
-        s[0] = 0;
     }
 }
 
-void handle_keypress_event(XEvent * e)
+static void handle_keypress_event(XEvent * e __attribute__ ((unused)))
 {
     XEvent event;
     XGrabKey(display, AnyKey, AnyModifier, root, True, GrabModeAsync, GrabModeAsync);
         XMaskEvent (display, KeyPressMask, &event);
     XDefineCursor(display, selected, (XCreateFontCursor(display, CURSOR)));
     unsigned int key = XLookupKeysym((XKeyEvent *) &event, 0);
-    if (key >= '0' && key <= '9')
+    if (isdigit(key))
     {
         XUngrabKey(display, AnyKey, AnyModifier, root);
         grab_keyboard();
@@ -225,55 +240,60 @@
                 message("Can't access next window!");
             }
             break;
-                default:
-                        message("Key \"%c\" is unbound!", (char)key);
+        default:
+            message("Key \"%c\" is unbound!", (char)key);
     }
 
     XUngrabKey(display, AnyKey, AnyModifier, root);
     grab_keyboard();
     XSetInputFocus (display, selected, RevertToParent, CurrentTime);
 }
-void message(const char *text, ...)
-{
-    char tmp[256];
-    va_list vl;
-    va_start(vl, text);
-    vsprintf(tmp, text, vl);
-    va_end(vl);
-    tmp[strlen(tmp)] = 0;
-        
-    int th = TextHeight(fontstruct);
-    int char_width = TextWidth(fontstruct, " ");
-    int win_width = (strlen(tmp) * char_width) + (WLISTPADDING * 2);        
-    int win_height = th;
-    int win_x, win_y;
+
+static void get_wlistpos(int *win_x, int *win_y, int win_width, int win_height) {
     switch(WLISTPOS)
         {
             case 0:
-                win_x = PADDING_WEST;
-                win_y = PADDING_NORTH;
+                *win_x = PADDING_WEST;
+                *win_y = PADDING_NORTH;
                 break;
             case 1:
-                win_x = SCREEN_WIDTH - PADDING_EAST - win_width - (BORDER * 2);
-                win_y = PADDING_NORTH;
+                *win_x = SCREEN_WIDTH - PADDING_EAST - win_width - (BORDER * 2);
+                *win_y = PADDING_NORTH;
                 break;
             case 2:
-                win_x = 0 + SCREEN_WIDTH - PADDING_EAST - win_width;
-                win_y = 0 + SCREEN_HEIGHT - PADDING_SOUTH - win_height;
+                *win_x = 0 + SCREEN_WIDTH - PADDING_EAST - win_width;
+                *win_y = 0 + SCREEN_HEIGHT - PADDING_SOUTH - win_height;
                 break;
             case 3:
-                win_x = PADDING_WEST;
-                win_y = 0 + SCREEN_HEIGHT - PADDING_SOUTH - win_height;
+                *win_x = PADDING_WEST;
+                *win_y = 0 + SCREEN_HEIGHT - PADDING_SOUTH - win_height;
                 break;
             case 4:
-                win_x = (SCREEN_WIDTH / 2) - (win_width / 2);
-                win_y = (SCREEN_HEIGHT / 2) - (win_height / 2);
+                *win_x = (SCREEN_WIDTH / 2) - (win_width / 2);
+                *win_y = (SCREEN_HEIGHT / 2) - (win_height / 2);
                 break;
             default:
-                win_x = PADDING_WEST;
-                win_y = PADDING_NORTH;
+                *win_x = PADDING_WEST;
+                *win_y = PADDING_NORTH;
                 break;
         }
+}
+
+static void message(const char *text, ...)
+{
+    char tmp[256];
+    va_list vl;
+    va_start(vl, text);
+    vsnprintf(tmp, sizeof(tmp), text, vl);
+    va_end(vl);
+    tmp[strlen(tmp)] = '\0';
+        
+    int th = TextHeight(fontstruct);
+    int char_width = TextWidth(fontstruct, " ");
+    int win_width = (strlen(tmp) * char_width) + (WLISTPADDING * 2);        
+    int win_height = th;
+    int win_x, win_y;
+    get_wlistpos(&win_x, &win_y, win_width, win_height);
     Window message_window = XCreateSimpleWindow(display, root, win_x,  win_y, win_width, win_height, BORDER, name2color(FGCOLOR), name2color(BGCOLOR));
     XSetWindowBorderWidth(display, message_window, BORDER);        
     XSetWindowBorder(display, message_window, name2color(SELBGCOLOR));        
@@ -283,13 +303,10 @@
     sleep(TIMEOUT);
     XFlush(display);
     if(message_window)
-    {
         XDestroyWindow(display, message_window);
-    }
 }
 
-
-void list_windows()
+static void list_windows(void)
 {
     int th, ypos, x;
         th = TextHeight(fontstruct);
@@ -298,12 +315,12 @@
     char *tmp;
     char title[256];
     int number = 0;
-    int max_title = 0;
+    size_t max_title = 0;
     XWindowAttributes winattr;
     Window root_return;
     int char_width = TextWidth(fontstruct, " ");
 
-     for (x = 0; x< max_windows; x++)
+     for (x = 0; x < max_windows; x++)
     {
         if(windows_container[x] != None)
         {
@@ -315,12 +332,11 @@
                         number++;
                         if(windows_container[x] == selected)
                         {    
-                            sprintf(title, "%d - %s", get_position(windows_container[x]), tmp);
-                        } else {
-                            sprintf(title, "%d - %s", get_position(windows_container[x]), tmp);
+                            snprintf(title, sizeof(title), "%d - %s", get_position(windows_container[x]), tmp);
+                            if(strlen(title) > max_title)
+                                max_title = strlen(title);
+                            title[0] = 0;
                         }
-                        if(strlen(title) > max_title) max_title = strlen(title);
-                        title[0] = 0;    
                     }
                 }
             }
@@ -330,33 +346,8 @@
         int win_width = (max_title * char_width) + (WLISTPADDING * 2);        
         int win_height = number * th;
         int win_x, win_y;
-        switch(WLISTPOS)
-        {
-            case 0:
-                win_x = PADDING_WEST;
-                win_y = PADDING_NORTH;
-                break;
-            case 1:
-                win_x = SCREEN_WIDTH - PADDING_EAST - win_width - (BORDER * 2);
-                win_y = PADDING_NORTH;
-                break;
-            case 2:
-                win_x = 0 + SCREEN_WIDTH - PADDING_EAST - win_width;
-                win_y = 0 + SCREEN_HEIGHT - PADDING_SOUTH - win_height;
-                break;
-            case 3:
-                win_x = PADDING_WEST;
-                win_y = 0 + SCREEN_HEIGHT - PADDING_SOUTH - win_height;
-                break;
-            case 4:
-                win_x = (SCREEN_WIDTH / 2) - (win_width / 2);
-                win_y = (SCREEN_HEIGHT / 2) - (win_height / 2);
-                break;
-            default:
-                win_x = PADDING_WEST;
-                win_y = PADDING_NORTH;
-                break;
-        }
+        get_wlistpos(&win_x, &win_y, win_width, win_height);
+
         WINDOW_LIST_WINDOW = XCreateSimpleWindow(display, root, win_x,  win_y, win_width, win_height, BORDER, name2color(FGCOLOR), name2color(BGCOLOR));
         XSetWindowBorderWidth(display, WINDOW_LIST_WINDOW, BORDER);        
         XSetWindowBorder(display, WINDOW_LIST_WINDOW, name2color(SELBGCOLOR));        
@@ -373,17 +364,22 @@
                         {
                             if(windows_container[x] == selected)
                             {
-                                sprintf(title, "%d - %s", get_position(windows_container[x]), tmp);
+                                snprintf(title, sizeof(title), "%d - %s", get_position(windows_container[x]), tmp);
                                 XFillRectangle(display, WINDOW_LIST_WINDOW, BARE_SELECTEDBG_GC, 0, ypos - th  + fontstruct->max_bounds.descent, win_width, th);
                                 XDrawString(display, WINDOW_LIST_WINDOW, BARE_SELECTEDFG_GC, WLISTPADDING, ypos, title, strlen(title));
                                 ypos+=th;
                             } else {
-                                sprintf(title, "%d - %s", get_position(windows_container[x]), tmp);
+                                snprintf(title, sizeof(title), "%d - %s", get_position(windows_container[x]), tmp);
                                 XDrawString(display, WINDOW_LIST_WINDOW, BARE_GC, WLISTPADDING, ypos, title, strlen(title));
                                 ypos+=th;
                             }
-                        title[0] = 0;
+                        
+                        } else {
+                            snprintf(title, sizeof(title), "%d - %s", get_position(windows_container[x]), tmp);
+                            XDrawString(display, WINDOW_LIST_WINDOW, BARE_GC, WLISTPADDING, ypos, title, strlen(title));
+                            ypos+=th;
                         }
+                        title[0] = 0;
                     }
             }
         }
@@ -399,7 +395,7 @@
     }
 }
 
-int select_window(int window)
+static int select_window(int window)
 {
     if(windows_container[window] != None)
     {
@@ -408,12 +404,12 @@
         XSetInputFocus(display, windows_container[window], RevertToParent, CurrentTime);
         selected = windows_container[window];
         return 0;
-    } else {
-        return -1;
     }
+    
+    return -1;
 }
 
-int get_free_position()
+static int get_free_position(void)
 {
     int x;
     for(x = 0; x < max_windows; x++)
@@ -424,9 +420,11 @@
             return x;
         }
     }
+
     return -1;
 }
-int get_position(Window window)
+
+static int get_position(Window window)
 {
     int x;
     for(x = 0; x < max_windows; x++)
@@ -440,7 +438,7 @@
     return -1;
 }
 
-int free_position(Window window)
+static int free_position(Window window)
 {
     int x;
     for(x = 0; x < max_windows; x++)
@@ -454,7 +452,7 @@
     return 1;
 }
 
-void handle_maprequest_event(XEvent *e)
+static void handle_maprequest_event(XEvent *e)
 {
     XMapWindow(display, e->xmaprequest.window);
     XMoveResizeWindow(display, e->xmaprequest.window, PADDING_WEST, PADDING_NORTH, SCREEN_WIDTH - PADDING_WEST - PADDING_EAST, SCREEN_HEIGHT - PADDING_NORTH - PADDING_SOUTH);
@@ -464,14 +462,13 @@
     windows_container[get_free_position()] = selected;
 }
 
-void handle_destroy_event(XEvent *e)
+static void handle_destroy_event(XEvent *e)
 {
     free_position(e->xdestroywindow.window);
     XDestroyWindow(display, e->xdestroywindow.window);
 }
 
-
-void handle_configure_event(XEvent *e)
+static void handle_configure_event(XEvent *e)
 {
       e->xconfigurerequest.type = ConfigureNotify;
       e->xconfigurerequest.x = 0;
@@ -484,19 +481,19 @@
       XSendEvent(display, e->xconfigurerequest.window, False, StructureNotifyMask, (XEvent*)&e->xconfigurerequest);
 }
 
-void handle_expose_event(XEvent *e)
+static void handle_expose_event(XEvent *e __attribute__ ((unused)))
 {
     // Redraw stuff in here...window title etc
     // Not handled yet but I'ma add it here for future dev
 }
 
-void handle_property_event(XEvent *e)
+static void handle_property_event(XEvent *e __attribute__ ((unused)))
 {
     // In case properties like name etc change ... handle them in here
     // Not handled yet but I'ma add it here for future dev
 }
 
-int handle_x_error(Display *display, XErrorEvent *e)
+static int handle_x_error(Display *disp __attribute__ ((unused)), XErrorEvent *e)
 {
     LOG_DEBUG("Xevent error: %d\n", e->error_code);
     LOG_DEBUG("Operation: %d\n", e->request_code);
@@ -504,7 +501,7 @@
     return 0;
 }
 
-void main_loop()
+static void main_loop(void)
 {
     XEvent event;
     XSetErrorHandler(handle_x_error); //Ignore X errors otherwise the WM would crash every other minute :)
@@ -541,8 +538,10 @@
     }
 }
 
-int main(int argc, char *argv[])
+int main(void)
 {
+    struct sigaction act;
+
     if(!(display = XOpenDisplay(DISPLAY))){
         LOG("BARE: cannot open display! Ending session.\n");
         return -1;
@@ -582,6 +581,12 @@
     BARE_colormap = DefaultColormap(display, 0);
     init_gc();
     message("Welcome to Bare WM v%s", VERSION);
+
+    act.sa_handler = sighandler;
+    sigemptyset(&act.sa_mask);
+    act.sa_flags = SA_RESTART;
+    sigaction(SIGCHLD, &act, NULL);
+
     main_loop();
 
     XFree(BARE_GC);
@@ -589,3 +594,4 @@
     XCloseDisplay(display);
     return 0;
 }
+

Offline

#28 2009-04-29 14:43:10

Wra!th
Member
Registered: 2009-03-31
Posts: 342

Re: Bare Window Manager (ex-MMWM)

Thanks a lot mate I will take this patch into consideration. Well it's just a tiny project of mine I don't expect it to grow into anything, si the windows list is not too much bother for now smile
I'm not an xlib OR a C guru...so there's bound to be some serious crap lying around this code

Hm...for some reason patching fails..I guess it's hard with source constantly changing. I'll try to backtrace your changes
Lot's of the changes you've made kinda leave me in the dark...Not sure if I'll use them or be able to use them. I have a habit of not modifying stuff I don't understand. You just have a different way of coding.

I'll try to learn something from the patch though

Last edited by Wra!th (2009-04-29 14:51:52)


MacGregor DESPITE THEM!
7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00

Offline

#29 2009-04-29 14:55:49

dimigon
Member
Registered: 2009-03-07
Posts: 139
Website

Re: Bare Window Manager (ex-MMWM)

Wra!th wrote:

Thanks a lot mate I will take this patch into consideration. Well it's just a tiny project of mine I don't expect it to grow into anything, si the windows list is not too much bother for now smile
I'm not an xlib OR a C guru...so there's bound to be some serious crap lying around this code

Hm...for some reason patching fails..I guess it's hard with source constantly changing. I'll try to backtrace your changes
Lot's of the changes you've made kinda leave me in the dark...Not sure if I'll use them or be able to use them. I have a habit of not modifying stuff I don't understand. You just have a different way of coding.

I'll try to learn something from the patch though

Hmm strange, I've applied it myself using patch < barewm.patch, unfortunately I do not have the original files that I worked on.

[EDIT] well the most important bit in the patch is the sighandler function and the sigaction stuff in main (for the zombies).

Last edited by dimigon (2009-04-29 15:00:39)

Offline

#30 2009-04-29 15:15:47

Wra!th
Member
Registered: 2009-03-31
Posts: 342

Re: Bare Window Manager (ex-MMWM)

dimigon wrote:
Wra!th wrote:

Thanks a lot mate I will take this patch into consideration. Well it's just a tiny project of mine I don't expect it to grow into anything, si the windows list is not too much bother for now smile
I'm not an xlib OR a C guru...so there's bound to be some serious crap lying around this code

Hm...for some reason patching fails..I guess it's hard with source constantly changing. I'll try to backtrace your changes
Lot's of the changes you've made kinda leave me in the dark...Not sure if I'll use them or be able to use them. I have a habit of not modifying stuff I don't understand. You just have a different way of coding.

I'll try to learn something from the patch though

Hmm strange, I've applied it myself using patch < barewm.patch, unfortunately I do not have the original files that I worked on.

[EDIT] well the most important bit in the patch is the sighandler function and the sigaction stuff in main (for the zombies).

Yeah I'll add those to the main source and credit you smile. I may need to do some cleaning anyway. I have useless {}'s at places (you guessed where they are I see), so those need to go. Also need some optimize the functions that calculate too much crap (like list_windows() and message()). I'll do a separate routine that calculates everything. Thanks for your input smile


MacGregor DESPITE THEM!
7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00

Offline

#31 2009-04-29 15:24:19

dimigon
Member
Registered: 2009-03-07
Posts: 139
Website

Re: Bare Window Manager (ex-MMWM)

[NOTE] use act.sa_flags = SA_NOCLDSTOP | SA_RESTART instead of act.sa_flags = SA_RESTART, so now the handler will be invoked only for terminated children and not for stopped ones. SA_RESTART affects the way read/write etc. behaves when it is interrupted by a signal.

Last edited by dimigon (2009-04-29 16:15:14)

Offline

#32 2009-04-29 16:50:38

Wra!th
Member
Registered: 2009-03-31
Posts: 342

Re: Bare Window Manager (ex-MMWM)

dimigon wrote:

[NOTE] use act.sa_flags = SA_NOCLDSTOP | SA_RESTART instead of act.sa_flags = SA_RESTART, so now the handler will be invoked only for terminated children and not for stopped ones. SA_RESTART affects the way read/write etc. behaves when it is interrupted by a signal.

done and updated smile
I have only one question regarding your patch: you made all the function static. Why? (not saying it was wrong..just need to learn why that is better). I remember static making the functions available only in the file they're defined in. Am I right? is that the reason?!


MacGregor DESPITE THEM!
7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00

Offline

#33 2009-04-29 16:59:39

dimigon
Member
Registered: 2009-03-07
Posts: 139
Website

Re: Bare Window Manager (ex-MMWM)

Wra!th wrote:
dimigon wrote:

[NOTE] use act.sa_flags = SA_NOCLDSTOP | SA_RESTART instead of act.sa_flags = SA_RESTART, so now the handler will be invoked only for terminated children and not for stopped ones. SA_RESTART affects the way read/write etc. behaves when it is interrupted by a signal.

done and updated smile
I have only one question regarding your patch: you made all the function static. Why? (not saying it was wrong..just need to learn why that is better). I remember static making the functions available only in the file they're defined in. Am I right? is that the reason?!

Yes, since they are not going to be called from a different translation unit there is no reason to be exported. This is a standard guideline and it makes a difference in large projects where exporting symbols is inefficient. It pollutes the namespace with function names which should not be called from outside.

[EDIT] you might be interested in this paper http://people.redhat.com/drepper/dsohowto.pdf

Last edited by dimigon (2009-04-29 17:04:30)

Offline

#34 2009-05-01 05:54:34

droog
Member
Registered: 2004-11-18
Posts: 877

Re: Bare Window Manager (ex-MMWM)

Wra!th wrote:

edit: actually I extracted the resulting tar.gz and it's just a folder, no binary no nothing

try this:

make  || return 1
install -d $pkgdir/usr/bin
install -c barewm $pkgdir/usr/bin/barewm


I tried this the other day and it worked great.
I just dont like having everything full screen on a widescreen monitor or i'd use this.

Offline

#35 2009-05-29 05:36:11

Hide
Member
From: Castalia
Registered: 2007-02-02
Posts: 368

Re: Bare Window Manager (ex-MMWM)

I'm really interested in this project so I'd like to know what its status is smile

Offline

#36 2009-05-29 05:53:53

Wra!th
Member
Registered: 2009-03-31
Posts: 342

Re: Bare Window Manager (ex-MMWM)

Hide wrote:

I'm really interested in this project so I'd like to know what its status is smile

Had a serious amount of projects to do lately so didn't have time to work on this, but will start soon smile


MacGregor DESPITE THEM!
7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00

Offline

#37 2009-05-30 07:44:53

Hide
Member
From: Castalia
Registered: 2007-02-02
Posts: 368

Re: Bare Window Manager (ex-MMWM)

Oh, awesome. Keep up the good work smile

Offline

#38 2009-10-14 12:21:03

Lich
Member
Registered: 2009-09-13
Posts: 437

Re: Bare Window Manager (ex-MMWM)

Ok boys, Bare WM is back on the table. Sorry I shelved it for so long, but I intend to make this a working product. Obviouslly it's not the best code out there, so I expect input from any of you
http://github.com/lich0x2b/barewm
tMmpsNg

Last edited by Lich (2009-10-14 12:40:18)


Archlinux | ratpoison + evilwm | urxvtc | tmux

Offline

#39 2009-10-14 13:30:05

SpeedVin
Member
From: Poland
Registered: 2009-04-29
Posts: 955

Re: Bare Window Manager (ex-MMWM)

Lich wrote:

Ok boys, Bare WM is back on the table. Sorry I shelved it for so long, but I intend to make this a working product. Obviouslly it's not the best code out there, so I expect input from any of you
http://github.com/lich0x2b/barewm
http://omploader.org/tMmpsNg

Nice screnshot I want now to change current window in fullmode in XMonad wink

Wra!th wrote:

Working at this for a day now.
Basically it's a full screen window manager aimed to those who spend their day cycling through windows instead of having 10 onscreen at a time. It's a dumbed down version of Ratpoison's default behaviour (really dumbed down..I don't expect anyone to use it as a fulltime WM anytime soon).
For people who only use GNU Screen, Firefox  and/or Emacs all day long(like me), it could prove quite useful.
Not sure if this will ever have any type of tiling..I might make it work with some predefined layouts but not sure.
For now I'm concentrating on cleaning it a bit, adding window by number selection(right now you can only cycle through them with MOD+Tab) and I need to get it to ignore DOCK type applications(eg trays and whatnot).
Also a messaging system of some sort is a must.

So far it has keys to:
- pop a new terminal
- kill selected window
- cycle through windows
- pop a launcher menu (using dmenu by default)
- show a list of windows (working, but needs some enhancement)

Configurable options:
- launcher menu to run
- terminal to run
- font
- window list fg/bg color/selected window fg color/
- screen padding(how much space to leave unmanaged on all sides of the screen - you can see a 16 pixel gap on top of the screenie)
- window list position (one of the four corners)
Will post code as soon as I think it deserves sharing, for now here's a little "teaser"
http://omploader.org/tMWtzZA

Is there anyway to do that full mode current window chooser in XMonad ?
This idea is awesome wink


Shell Scripter | C/C++/Python/Java Coder | ZSH

Offline

#40 2009-10-14 13:42:38

Lich
Member
Registered: 2009-09-13
Posts: 437

Re: Bare Window Manager (ex-MMWM)

I don't exactly understand what your question is, but I do know that you have a wee bit of problems with English as it is not your native language.
You want windows in xmonad to be always maximized? I am sure xmonad has a layout for this (something like the dwm monocle). To make windows "cover" the gaps you might have on top, you just hide the status bar (there's a keybinding for that too, maybe MOD+b if I'm not mistaking). Sorry I don't have xmonad at hand now.


Archlinux | ratpoison + evilwm | urxvtc | tmux

Offline

#41 2009-10-14 13:46:15

SpeedVin
Member
From: Poland
Registered: 2009-04-29
Posts: 955

Re: Bare Window Manager (ex-MMWM)

Lich wrote:

I don't exactly understand what your question is, but I do know that you have a wee bit of problems with English as it is not your native language.
You want windows in xmonad to be always maximized? I am sure xmonad has a layout for this (something like the dwm monocle). To make windows "cover" the gaps you might have on top, you just hide the status bar (there's a keybinding for that too, maybe MOD+b if I'm not mistaking). Sorry I don't have xmonad at hand now.

I mean that I got full screen window in XMonad , but I don't have option to choose current window that are full (I mean I can switch full mode windows like on your screenshot smile)i.

Last edited by SpeedVin (2009-10-14 13:50:13)


Shell Scripter | C/C++/Python/Java Coder | ZSH

Offline

#42 2009-10-14 14:05:45

Lich
Member
Registered: 2009-09-13
Posts: 437

Re: Bare Window Manager (ex-MMWM)

Ooooh, yeah you are left with cycling them afaik. Too bad xmonad doesn't have the option to output windows to stdout like ratpoison (IN YOUR FACE XMONAD!:D), you could write a script with dmenu or ratmenu to get something similar.


Archlinux | ratpoison + evilwm | urxvtc | tmux

Offline

#43 2009-10-14 14:08:22

SpeedVin
Member
From: Poland
Registered: 2009-04-29
Posts: 955

Re: Bare Window Manager (ex-MMWM)

Lich wrote:

Ooooh, yeah you are left with cycling them afaik. Too bad xmonad doesn't have the option to output windows to stdout like ratpoison (IN YOUR FACE XMONAD!:D), you could write a script with dmenu or ratmenu to get something similar.

Oh Thanks that was really helpfull (Now I need someone to help) smile


Shell Scripter | C/C++/Python/Java Coder | ZSH

Offline

#44 2009-10-14 14:35:57

Lich
Member
Registered: 2009-09-13
Posts: 437

Re: Bare Window Manager (ex-MMWM)

barewm-git now in AUR


Archlinux | ratpoison + evilwm | urxvtc | tmux

Offline

#45 2009-10-14 14:42:27

Hide
Member
From: Castalia
Registered: 2007-02-02
Posts: 368

Re: Bare Window Manager (ex-MMWM)

Heh, been trying to tune Wra!th's PKGBUILD, and in the end I figured out there was a problem with Makefile (which is beyond my scope). Good thing you managed to fix it. Will give it a try smile

edit:
btw, dumb question: where is the conf.h file?

Last edited by Hide (2009-10-14 14:49:33)

Offline

#46 2009-10-14 14:58:19

Lich
Member
Registered: 2009-09-13
Posts: 437

Re: Bare Window Manager (ex-MMWM)

/me = Wra!th
well the conf.h file is in the barewm branch, I suck at PKGBUILDs so I asked wonder to make one for me. I'm not that good with AUR, but I would imagine you could edit something before it gets built? I'll look into this later


Archlinux | ratpoison + evilwm | urxvtc | tmux

Offline

#47 2009-10-14 15:06:57

Hide
Member
From: Castalia
Registered: 2007-02-02
Posts: 368

Re: Bare Window Manager (ex-MMWM)

Lich wrote:

/me = Wra!th

Oh, thought so, just wasn't sure.

Lich wrote:

well the conf.h file is in the barewm branch, I suck at PKGBUILDs so I asked wonder to make one for me. I'm not that good with AUR, but I would imagine you could edit something before it gets built? I'll look into this later

No need to do this. Just make a new folder (i.e. $HOME/.barewm) with all the necessary files for compilation. Here's an excerpt from the Wiki how it's done with dwm:

Browse to the dwm source code directory you saved during the installation process (~/dwm in the example). The config.h found within this directory is where the general dwm preferences are stored.
[...]
Once your changes have been made, edit the PKGBUILD file in the same directory and delete the contents of the md5sums array so that it looks like this:

md5sums=()

This will eliminate a checksum mismatch between the official config.h and your revised copy.

Now to compile and reinstall:

$ makepkg -efi

Assuming your changes were valid, this command will compile dwm, build and reinstall the resulting package (see makepkg -h for details).
[...]

Last edited by Hide (2009-10-14 15:08:51)

Offline

#48 2009-10-15 08:26:35

Lich
Member
Registered: 2009-09-13
Posts: 437

Re: Bare Window Manager (ex-MMWM)

As a side note, the version that's in aur now is like a pre-alpha, it's not intended for usage beyond the purpose of testing it. I started doing a complete cleanup, I have a ton of useless stuff in there, and some REALLY bad coding practices. Also working on a nice logo today smile. I know that should come after a good working release, but I need to practice my drawing so..this is the perfect opportunity.
Ok new version is in git now. It handles timer better, old mockup of the code used sleep, so any input would freeze. Using signals (SIGALRM in particular) to get the job done now (thanks for the info rob|). Did a bit of cleanup too, but the huge clean-up has just began. I have some serious problems in there. I would appreciate any tester's input

Last edited by Lich (2009-10-15 10:19:40)


Archlinux | ratpoison + evilwm | urxvtc | tmux

Offline

#49 2009-10-15 17:08:48

meth0dz
Member
Registered: 2009-10-15
Posts: 8

Re: Bare Window Manager (ex-MMWM)

I started reading through your code when I had a break today, and noticed some stuff that you can clean up.

1) It's generally better form to put all macros in all caps, and refrain from doing so to functions and other things that aren't macros.  This is to help other people out who are reading your code.

2) On line 110 (TextWidth) of your code you do this, "if(strlen(text) >= 1 && text != NULL)", but that doesn't make any sense.  If you want to avoid the exception raised from doing strlen(NULL) you need to switch the order inside the if statement to "if(text != NULL && strlen(text) >= 1)", but really what you should do is this "if(text && text[0])".

3) The function on line 117 (TextHeight) may be better served as a macro.

4) You can also clean the function on line 121 (name2color) up by doing this.

unsigned long name2color(const char *cid)
{
        XColor tmpcol;

        if(XParseColor(display, BARE_colormap, cid, &tmpcol)) {
                if(XAllocColor(display, BARE_colormap, &tmpcol)) 
                        return tmpcol.pixel;
        }
        
        LOG("Cannot allocate \"%s\" color. Defaulting to black!\n", cid);
        return BlackPixel(display, XDefaultScreen(display));

        
}

5) The function at line 137 (init_gc) should just be type void.

6) At line 157 (in get_prev_window), assuming that you are using C99 like a sane person, you can declare variables in your for statement (This applies throughout your code).
ex,

for (int i = 0; i < 10; i++)

7) As far as the functions at 154 (get_next_window) and 168 (get_prev_window), you should be able to combine them into one function, something like this.

// true = next, false = previous
int get_window(bool nex_prev)
{
        int x = get_position(selected)
        nex_prev ? x++ :  x--;
        while ( x >= 0 && x < max_windows) {
                if(windows_container[x] != None)
                {
                        LOG_DEBUG("Found next window at: %d\n", x);
                        return x;
                }
                nex_prev ? x++ :  x--;
         }
         return -1;
}

8) In your function at 181 (grab_keyboard), I can't really say that the way you have it is bad.  But personally I prefer explicit declarations when there are no parameters to a function so... int whatever(void) as opposed to int whatever().  The same applies throughout your code.

9) The function at 186 (echo_output) is a good example of a function that lacks error checking. In general you lack a lot of error checking, which you should fix.

10) The function at 206 (handle_keypress_event) also does no error checking, add it.

11) On line 213 (in handle_key_press_event) you are relying on the fact that whatever charset is in use will have numbers listed sequentially.  Use isnum() instead.

Bad = if (key >= '0' && key <= '9')

12) In general you should focus more on dynamic memory allocation as opposed to static memory.  So heap in favor of stack basically.

13) Line 339 (in list_windows)   makes me wonder what the purpose of max_title is.

if(strlen(title) > max_title) max_title = strlen(title);

If you are just going to adjust the max title whenever a longer title occurs what's the point?

14) Code in the function on line 315 (list_windows) seems redundant, like some shorter function(s) could be reused in it to clean it up.  I don't have time to really figure that out for sure right now though.

15) There is no need to have functions at line 428 (get_free_position) and line 441 (get_position) and line 455 (free_position) as they all do almost the same thing. 

16) Last thing I noticed is that you are very inconsistent with naming conventions for functions and variables.  You should sort this out, it will make your code much more pleasent to read.

Alright, those are the things that I noticed in about ~30 mins of scanning, however I need to get ready for class.  Feel free to ask about anything, either how to implement it, or if what I said was just wacky.

Offline

#50 2009-10-15 17:27:35

Lich
Member
Registered: 2009-09-13
Posts: 437

Re: Bare Window Manager (ex-MMWM)

WOW that was a huge input, I feel like I just got my midterm paper all red with corrections now smile.
Thanks alot for the time you've put into this, I was just doing that get next/prev thing now. You have to understand that this was just a (really bad!) mockup of the project. Your input is really appreciated! Thanks. I'll start fixing everything right now.

PS: Welcome to the forums

The max_title part is just a variable that I add to in case I hit a title that's longer than the current value. With that I build my window's size
As per my lament here http://bbs.archlinux.org/viewtopic.php?id=81868, I can see that my C skills are really poor. I knew I came to the right conclusions there

Regarding my definition of most functions as int, I usually do that in case I need to check a succesfull run of the function. Not always bad I guess.

Last edited by Lich (2009-10-15 17:40:54)


Archlinux | ratpoison + evilwm | urxvtc | tmux

Offline

Board footer

Powered by FluxBB