Archive for the ‘Uncategorized’ Category

FVWM: Moving a Window to Another Screen

Wednesday, October 7th, 2009

Probably the most lacking feature in most multi-screen setups is the ability to move a window from one screen to another with a keyboard shortcut. I do this to bring the window I’m currently working on into my centre monitor so its directly in front of me. There are 2 ways to go about this. The first is moving a window to a specific display and the second is to move (shift) the window to the left or right display (which would just be back and forth in a dual monitor setup).

For the first case you could define the following function:

# This function will move a window to the X screen provided in the
# first argument. If the window is in the maximized it will be taken
# out of the maximized state before moving. If we don’t do this it
# will be moved back to the original screen when the maximized state
# is toggled.
#
# If you do not want the pointer to be moved to the windows new
# location then comment out the line containing WarpToWindow.
DestroyFunc MoveWindowToScreen
AddToFunc MoveWindowToScreen
+ I Current (Maximized) Maximize
+ I SetEnv PWX $[pointer.wx]
+ I Setenv PWY $[pointer.wy]
+ I MoveToScreen $[0]
+ I WindowId $[w.id] WarpToWindow $[PWX]p $[PWY]p

And then add the following to your window operations menu:

+ “&1 Move to Screen 1″ MoveWindowToScreen 2
+ “&2 Move to Screen 2″ MoveWindowToScreen 0
+ “&3 Move to Screen 3″ MoveWindowToScreen 1

Note that the argument you provide to the MoveWindowToScreen function takes the X display number which may not directly map to the order of the screens on your desk.

The second method is to move the screen to the left or the right. Or in the case of a dual monitor setup you could just continually move right to have the window flip/flop between your 2 screens.

First download the following file and save it to ~/.fvwm/ShiftToScreen.py: ShiftToScreen.py
You will also need to update variables screenWidth and screens in ShiftToScreen.py as they are currently setup for my configuration of 3 screens with a width of 1920 pixels each.

Then define the following function:

# This function will move a window to the left or right screen
# depending on the first argument which should be on of “left” or
# “right”. It depends on the auxiliary python script
# ShiftToScreen.py.
DestroyFunc ShiftToScreen
AddToFunc ShiftToScreen
+ I Current (Maximized) Maximize
+ I SetEnv PWX $[pointer.wx]
+ I Setenv PWY $[pointer.wy]
+ I PipeRead “python $./ShiftToScreen.py $[0] $[w.x]”
+ I WindowId $[w.id] WarpToWindow $[PWX]p $[PWY]p

You could then add the following to your windows operations menu:

+ “&Left Screen” ShiftToScreen left
+ “&Right Screen” ShiftToScreen right

or define some keyboard shortcuts. For example I have bound Shift-Alt-Left and Shift-Alt-Right to shift the window to the left or right screen:

Key Left WTSF12468 SM ShiftToScreen left
Key Right WTSF12468 SM ShiftToScreen right

If you are only working with 2 screens you will only need to define one shortcut to get flip/flop like behaviour as shifting left beyond the leftmost screen will wrap the window around to the right most screen.

Enjoy.

Ideal Multi-Monitor Setup

Tuesday, September 22nd, 2009

Multi-monitor configurations are great but I think they leave out some usability aspects that could really make life easier for the keyboard user. When I was just using dual displays I really wanted keyboard shortcuts to do the following:

* Move a window from one screen to the other.
* Swap what is seen on each display.

When I moved to 3 monitors my needs changed a little.

* Shift a window to the screen to the left or the right, rotating around.
* Swap a display with the one to the left or the right.
* Shift all displays to the left or the right.

This would make it extremely fast to move the window you are currently working on to your primary display, then push it back to where it came from. Or swap the contents of your right screen with your centre screen if you need to shift your work focus for a while.

As far as I know this is not possible with Windows, Mac or most Linux configurations. However, I believe using FVWM as your Linux (ok, *nix) window manager will make this all possible, at least my experiments with dual screens have been positive. I’ll update this blog with various functions that should make all of the above achievable.

Making that Caps-Lock key an extra Control key

Monday, March 16th, 2009

Yes, covered everywhere and I’ve done it enough time I should know it off by heart now…  I used to swap caps and control, but now I just make the caps an additional control and leave the original control as is…

~/.xmodmap snippet:

remove Lock = Caps_Lock
keysym Caps_Lock = Control_L
add Control = Control_L

Moved to Victoria

Sunday, March 15th, 2009

Just a quick update to let everyone know that we are no longer live in Saskatoon but haved moved out to Victoria, BC.

Hello world!

Sunday, October 12th, 2008

Due to catatstrophic failures over at vpsville.ca I’m left without a server.  This was the first time I completely removed myself from managing my own servers, and it hasn’t turned out well.  Oh well, I think I will move to managed services for the next little while.

TAILQ Example

Saturday, August 19th, 2006

[Reposted on May 1, 2009 - recovered from old blog.]

I plan to use this blog to post codebits that I find myself sending to people over and over again. The first example is how to use a TAILQ from sys/queue.h found on the BSDs. Many Linux distributions also have sys/queue.h but may be missing certain macros such as TAILQ_FOREACH(). At the very least I hope this enticies some newer C programmer to use queue.h rather than rolling their own linked list. I’ll jump directly to the code as I feel it is more or less self explanatory.

The following code can be downloaded here.


/*
 * TAILQ example program.
 */

#include <stdlib.h>
#include <stdio.h>

/*
 * On many OpenBSD/NetBSD/FreeBSD you could include <sys/queue.h>, but
 * for portability we’ll include the local copy.
 */
#include "queue.h"

/*
 * This structure defines each item in our tail queue.  It must also
 * contain an item (TAILQ_ENTRY) that points to the next and previous
 * items in the tail queue.
 *
 * For simplicity, we will be creating a list of integers.
 */
struct tailq_entry {
        int value;

        /*
         * This holds the pointers to the next and previous entries in
         * the tail queue.
         */
        TAILQ_ENTRY(tailq_entry) entries;
};

/*
 * Our tail queue requires a head, this is defined using the
 * TAILQ_HEAD macro.
 */
TAILQ_HEAD(, tailq_entry) my_tailq_head;

int
main(int argc, char **argv)
{
        /* Define a pointer to an item in the tail queue. */
        struct tailq_entry *item;

        /* In some cases we have to track a temporary item. */
        struct tailq_entry *tmp_item;

        int i;

        /* Initialize the tail queue. */
        TAILQ_INIT(&my_tailq_head);

        /* Add 10 items to the tailq queue. */
        for (i = 0; i < 10; i++) {
                /*
                 * Each item we want to add to the tail queue must be
                 * allocated.
                 */
                item = malloc(sizeof(*item));
                if (item == NULL) {
                        perror("malloc failed");
                        exit(EXIT_FAILURE);
                }

                /* Set the value. */
                item->value = i;

                /*
                 * Add our item to the end of tail queue. The first
                 * argument is a pointer to the head of our tail
                 * queue, the second is the item we want to add, and
                 * the third argument is the name of the struct
                 * variable that points to the next and previous items
                 * in the tail queue.
                 */
                TAILQ_INSERT_TAIL(&my_tailq_head, item, entries);
        }

        /* Traverse the tail queue forward. */
        printf("Forward traversal: ");
        TAILQ_FOREACH(item, &my_tailq_head, entries) {
                printf("%d ", item->value);
        }
        printf("\n");

        /* Insert a new item after the item with value 5. */
        printf("Adding new item after 5: ");
        TAILQ_FOREACH(item, &my_tailq_head, entries) {
                if (item->value == 5) {
                        struct tailq_entry *new_item =
                            malloc(sizeof(*new_item));
                        if (new_item == NULL) {
                                perror("malloc failed");
                                exit(EXIT_FAILURE);
                        }
                        new_item->value = 10;

                        TAILQ_INSERT_AFTER(&my_tailq_head, item, new_item,
                            entries);
                        break;
                }
        }

        /* Do another forward traversal to show the newly added item. */
        TAILQ_FOREACH(item, &my_tailq_head, entries) {
                printf("%d ", item->value);
        }
        printf("\n");

        /*
         * Delete the item with the value 3.
         *
         * We can’t use TAILQ_FOREACH here as TAILQ_FOREACH is not
         * safe against deletions during the traversal.  Some variants
         * of queue.h have TAILQ_FOREACH_MUTABLE or TAILQ_FOREACH_SAFE
         * which are safe against deletions.
         */
        printf("Deleting item with value 3: ");
        for (item = TAILQ_FIRST(&my_tailq_head); item != NULL; item = tmp_item)
        {
                tmp_item = TAILQ_NEXT(item, entries);
                if (item->value == 3) {
                        /* Remove the item from the tail queue. */
                        TAILQ_REMOVE(&my_tailq_head, item, entries);

                        /* Free the item as we don’t need it anymore. */
                        free(item);

                        break;
                }
        }

        /* Another forward traversal to show that the value 3 is now gone. */
        TAILQ_FOREACH(item, &my_tailq_head, entries) {
                printf("%d ", item->value);
        }
        printf("\n");

        /* Free the entire tail queue. */
        while (item = TAILQ_FIRST(&my_tailq_head)) {
                TAILQ_REMOVE(&my_tailq_head, item, entries);
                free(item);
        }

        /* The tail queue should now be empty. */
        if (!TAILQ_EMPTY(&my_tailq_head))
                printf("tail queue is NOT empty!\n");

        return 0;
}