Metacity window-placement patch


Comments:


Update!

2009-06-25
Clearly, this page is in need of a serious overhaul. In the meantime, please note that the GNOME project has moved their code from Subversion to Git (http://git.gnome.org/).[1] So I made a copy of their Git repository on GitHub. Specifically, the official Metacity repo is currently here: http://git.gnome.org/cgit/metacity/. I pushed copies of their master and gnome-2-26 branches to my own metacity repository on GitHub. Then I reimplemented my center-placement changes on a new branch called gnome-2-26-center-placement for the GNOME 2.26 release of Metacity: http://github.com/ccg/metacity/tree/gnome-2-26-center-placement I'd be happy to write up instruction on how to straddle two git remote repositories like that if anybody is interested. If you're a new Git user, it's probably not immediately obvious how to do something like that. It took me a few weeks of day-to-day use to become comfortable with Git.


Downloads

New, simple patch that only implements center placement

For Metacity 2.14.5:

Old, fancy patch with all the options

For Metacity 2.12:

For Metacity 2.10:

For Metacity 2.8:


Description

New, simple patch

This patch modifies Metacity's window-placement behavior so that it merely centers new windows instead of trying to tile them in groups or cascade them from the upper-left corner.

Old, fancy patch

This patch for Metacity adds a few window-placement options that can be configured in the graphical gconf-editor or with the gconftool-2 command-line program.

The following options are available:

"first_fit" ("smart" is also accepted)
This is the default Metacity window-placement behavior. In this mode, Metacity will attempt to tile new windows on the screen so that they do not overlap.
"cascade"
This skips Metacity's center/tile behavior and cascades new windows the upper-left corner of the current desktop. It uses Metacity's built-in cascading algorithm.
"center"
This option will cause Metacity to place each new window at the center of its workspace.
"origin"
In this mode, Metacity will simply place each new window at the origin (the upper-left corner) of its workspace.
"random"
In this mode, Metacity will choose a random position on the screen for a new window.

After installing the patched version of Metacity, you can change the option as follows:

In GNOME 2.10, open Configuration Editor from the following menu:
Applications --> System Tools --> Configuration Editor
Then navigate to the placement_mode key:
/ --> apps --> metacity --> general
Right-click on "placement_mode", choose "Edit Key..." from the pop-up menu, and then set the "Value:" field to the option you want.

To change the option from the command line, do this:
gconftool-2 --type string --set /apps/metacity/general/placement_mode random
(but replace "random" with whichever option you want).


Build and install in a home directory

I like to avoid clutter in my home directory by installing locally built apps into $HOME/opt/name-version. In this case, it would be something like $HOME/opt/metacity-2.16.3. After patching the source:

./configure --prefix=$HOME/opt/metacity-2.16.3
make
export GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL=1
make install
unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL

I usually point my local copy of metacity at the system-wide theme directory:

cd ~/opt/metacity-2.16.3/share
mv themes themes.original
ln -s /usr/share/themes .

After running make, you can test your build by running metacity --replace from the source directory. You should be able to do this before or after installing.

If everything works, you can make the change permanent by adding a line like the following to ~/.gnomerc:

export WINDOW_MANAGER=$HOME/opt/metacity-2.16.3/bin/metacity


Building a custom RPM

Good introductory article: Packaging software with RPM, Part 1 ... Part 2 ... Part 3

In the steps below, 'rpm/' refers to your rpm build directory. I use ~/rpm, as described in the article above. ("%_topdir /home/chad/rpm" in ~/.rpmmacros)

Note:Your setup and commands may be different. This is not written as a copy-and-paste sort of command list. This is just a rough guide.

  1. Download your distro's metacity source rpm (SRPM).
  2. Install the SRPM.
  3. Copy patch file to rpm/SOURCES directory.
  4. Edit the SPECS/metacity.spec file. For example, here is my SPEC file for my Fedora Core 4, Metacity 2.10.0 RPM.
    1. Add a patch line like this:
      Patch2: metacity-2.10-window-placement.patch
    2. Add a patch command:
      %patch2 -p1 -b .placement
    3. Update the %changelog section with something like this:
      * Wed Jul 13 2005 Your Name <email@example.com> 2.10.0-2
      - Added window-placement patch (http://glendenin.com/chad/metacity/)

      Changelog date format: date +"%a %b %d %Y"

  5. cd rpm/SPECS; rpmbuild -ba metacity.spec
  6. cd rpm/RPMS/i386
  7. sudo rpm -Uvh metacity-2.10.0-2.i386.rpm


Building a custom .DEB package (for Debian, Ubuntu, etc.)

Debian Package Customization HOWTO

I did the following on Ubuntu 5.10. Modify as needed for other Debian-based distros.

Make sure these packages are already installed (install them if not):

cd <your build directory>
apt-get source metacity;
sudo apt-get build-dep metacity;
export DEBEMAIL=your_address@example.com # Modify as needed;
cd metacity-2.12.1/;
debchange --nmu

At this point, a text editor will open where you can add an entry to the changelog file. See http://familiasanchez.net/~roberto/howtos/debcustomize for some suggestions. Note the modified release number. My new entry looks like this:
metacity (1:2.12.1-0ubuntu1.0.0.ccg.0) breezy; urgency=low

  * Non-maintainer upload.
  * Applied window-placement patch. (http://glendenin.com/chad/metacity/)

 -- Chad Glendenin <ccg_spam@example.com>  Thu, 20 Oct 2005 14:48:27 -0500

Copy the patch file (see above) into metacity-2.12.1/debian/patches/. I renamed the patch to 003_placement.patch to appear consistent with the other patches I found in that directory. I don't know if that's really necessary (I doubt it, but I don't care enough to find out). Then in the metacity-2.12.1 directory:
debuild -us -uc
cd ..
sudo dpkg -i metacity_2.12.1-0ubuntu1.0.0.ccg.0_i386.deb


Instructions for compiling with custom ebuild on Gentoo

NOTE: I have not updated these commands for Metacity 2.10, but it should be similar.

These commands need to be run as root, or preceded with a sudo.

Add this line to your /etc/make.conf:
PORTDIR_OVERLAY="/usr/local/portage"

Create the directory:
mkdir -p /usr/local/portage/x11-wm

Copy the official metacity build dir over:
cp -a /usr/portage/x11-wm/metacity /usr/local/portage/x11-wm/

Add the patch(es) to the files directory:
cp metacity-2.8.6-window-placement.patch /usr/local/portage/x11-wm/metacity/files/

Replace the ebuild file:
cp -f metacity-2.8.6-r1.ebuild /usr/local/portage/x11-wm/metacity/
(Or just manually add the epatch line to the src_unpack function.)

Update the digest/manifest:
ebuild metacity-2.8.6-r1.ebuild digest

Now you should be able to rebuild Metacity using the usual Portage tools.


[1] Yay! Everybody knows that Git is the new hotness. Nobody knows why, but everybody agrees. Actually, git is pretty cool once you get past the UI weirdness. How do you switch branches? git checkout branch-name How do you revert a file back to its old version? git checkout file-name No, I'm not joking. How do you delete a remote branch? git push origin :branch-name WTH?