November 6th, 2007 Pekk
Here’s a quick fix to change metacity’s <Alt> + Middle Click resize to <Alt> + Left click to resize. Nikolay, a friend of mine found a patch file for it on the web, the code’s pretty simple just swapping a couple of numbers. I just read a few lines from the file he discovered on someone’s blog. I didn’t really bother to read the rest of it but Nikolay explained a bit more on how to build a deb package from the source and install it once the modifications are applied.
If you don’t want to get your hands dirty on compiling you can try installing my version using dpkg -i metacity_2.20.0-0ubuntu3_i386.deb once you download the file. I do not guarantee this file in any way, use it at your own risk. Follow on to learn how to patch it yourself.
First install the following packages. I used apt-get from the terminal, since I’m on Ubuntu (root permission is required):
$ sudo apt-get build-dep metacity
$ sudo apt-get install devscripts debhelper fakeroot
Now CD to the directory that you want to download the metacity source files to and type:
$ sudo apt-get source metacity
You won’t have permissions to the source files, so you will have to either edit them as root, or chown them to your user:
$ sudo chown -R metacity*
once you’re ready, cd to the metacity/src folder (in my case it was metacity-2.0/src). Now you have to make a change in the display.c source file, on my version of the source it’s line 1665 so it should probably still be around there. Use any text editor that you’re comfortable with (I used vim). The original line looks as follows:
else if (!unmodified && event->xbutton.button == 2)
{
if (window->has_resize_func)
{
gboolean north, south;
gboolean west, east;
int root_x, root_y;
MetaGrabOp op;
Change this to:
else if (!unmodified && event->xbutton.button == 3)
{
if (window->has_resize_func)
{
gboolean north, south;
gboolean west, east;
int root_x, root_y;
MetaGrabOp op;
And then the next change should be the next else if that’s connected to our currently modified if. Around line 1714 in my code looks like this:
else if (event->xbutton.button == 3)
{
if (meta_prefs_get_raise_on_click ())
meta_window_raise (window);
meta_window_show_menu (window,
event->xbutton.x_root,
event->xbutton.y_root,
event->xbutton.button,
event->xbutton.time);
}
Make it look like this:
else if (event->xbutton.button == 2)
{
if (meta_prefs_get_raise_on_click ())
meta_window_raise (window);
meta_window_show_menu (window,
event->xbutton.x_root,
event->xbutton.y_root,
event->xbutton.button,
event->xbutton.time);
}
If you want to test drive your changes before making anything permanent you can optionally make a test build, from terminal:
metacity/src $ cd ..
metacity/ $ make
metacity $ ./src/metacity –replace
This will (1) build metacity and (2) run it by replacing the currently opened process with the new one we built. try moving the terminal window around with the new left-click mod for a bit to make sure it works, when you’re satisfied send the break command with Ctrl+C to kill the process, and your original metacity will reopen.
Now we are going to build our very own debian package. Why? I don’t know but this is how Nikolay suggested to do it, I was going to just do a make install when the compiling finished after I’d tested it, but he told me to do it this way so I didn’t question it. At least this way you’ll have a deb package to distribute to your friends.
At the terminal in the metacity/ directory type:
$ debuild -us -uc
It will now recompile everything for you and place a bunch of deb packages in one directory up from the current. (i.e., if the metacity source path is ~/src/metacity then the deb packages will be placed in ~/src)
Now install the deb packages with dpkg:
dpkg -i name_of_your_metacity_package.deb
There will be a few deb files, make sure you get the one that says metacity and not libmetacity.
I will also post a patch file when I finally remember how to correctly use patch (or maybe I’m just not creating the diffs right, either way I will post back soon).
Another easy way to make this change is to apply the following diff. To do this, place the patch file in the same directory as your display.c (in the metacity/src path) and issue the command:
patch < right-click-resize.patch
from a terminal window. The patch was created as a context diff (diff -c) so if patch won’t take this (though it did for me) you can try an explicit call as follows:
patch -p0 -c < right-click-resize.patch
Happy Hacking!
Posted in Ubuntu, Linux | 2 Comments »