Thursday, October 13, 2011

Customizing Unity 2D, Ubuntu Natty / Oneiric

Unity 2D is the default fallback session from Ubuntu Oneiric 11.10 onwards. In Natty 11.04, you'd need to manually install the package 'unity-2d', available in the official repositories, as it doesn't come bundled with Natty. Unity 2D now almost resembles the regular Unity, just lacking a few eye-candy effects. However, those can be added as well by running Unity 2D with Compiz instead of Metacity. You'd need a 3D-accelerated graphics card and proper drivers to enable Compiz in Unity 2D.


Unity 2D is a lighter version, in fact just a QT application in contrast to the regular Unity, which runs as a Compiz plugin. For older machines which are slow/lagging with Unity, Unity 2D is a blessing.

Unity itself can't be customized to an extreme level as used to be the case with Gnome 2.x, and it is even worse with Unity 2D, which still lacks some of the few options that are available for Unity. Anyway, there are a few methods of tweaking the Launcher, icons, etc., so we'll discuss those.

Updated GUI for Unity 2D's Settings

At the time of the release of Natty Narwhal, Mariano Chavero has developed a simple GUI for changing the few available settings of Unity 2D, as well as some other desktop features. These settings could also be changed via GConf-Editor in Natty, or via DConf-Editor in Oneiric. But, you might guess it already :P , it's way easier to do that via a simple, dedicated GUI.


As Unity 2D has shifted to using DConf for its settings, Mariano's version doesn't work with Oneiric, and he hasn't released an Oneiric version yet. So Krytarik modified his script to work with Oneiric, and also removed the session dependency. Please see here for full details and how to install it:

http://www.tuxgarage.com/2011/10/gui-for-changing-unity-2d-settings.html

Rearrange Application Launchers

To rearrange the application launchers in the Launcher, click and hold down the left mouse button for ca. 1 second at whichever launcher you want to re-locate. You'd notice that the icon would separate itself from the Launcher after that time, and then you can drag it to your desired location in the Launcher (within the area designated for application launchers).


System-Wide Tweaks

All of the tweaks outlined below are system-wide, and require a restart of the Launcher to take effect. Obviously, it's a good idea to back up the concerning default system files before tinkering with them!

Some of the tweaks were sourced from here.

Notes: These tweaks are based on Oneiric's version of Unity 2D, so some of them don't fully or at all apply to Natty's version. Also, your changes will be reverted when the concerning packages are updated!

Back Up Default Settings

Before you start playing with any of the below teaks, back up the concerning default system files:

sudo cp /usr/share/unity-2d/launcher/Launcher.qml /usr/share/unity-2d/launcher/Launcher.qml.default
sudo cp /usr/share/unity-2d/launcher/LauncherItem.qml /usr/share/unity-2d/launcher/LauncherItem.qml.default
sudo cp /usr/share/unity-2d/launcher/artwork/background.png /usr/share/unity-2d/launcher/artwork/background.png.default

If at some point you want to restore the default Launcher settings, just run these commands:

sudo cp /usr/share/unity-2d/launcher/Launcher.qml.default /usr/share/unity-2d/launcher/Launcher.qml
sudo cp /usr/share/unity-2d/launcher/LauncherItem.qml.default /usr/share/unity-2d/launcher/LauncherItem.qml
sudo cp /usr/share/unity-2d/launcher/artwork/background.png.default /usr/share/unity-2d/launcher/artwork/background.png

Restart the Launcher

When you are done with your customization, either simply relogin, or enter this command to make the Launcher restart:

killall unity-2d-launcher

If it doesn't restart automatically, just run:

setsid unity-2d-launcher

Remove / Rearrange Static Launcher Items

If you want to get rid of or re-locate a static Launcher item (not an application launcher), you need to edit the 'Launcher.qml' under the '/usr/share/unity-2d' directory. But before, back it up as described above.

gksudo gedit /usr/share/unity-2d/launcher/Launcher.qml

Find this section:

Component.onCompleted: {
    items.appendModel(bfbModel);
    items.appendModel(applications);
    items.appendModel(workspaces);
    items.appendModel(devices);
    items.appendModel(trashes);
}

Where is:
  • items.appendModel(bfbModel); = Dash Button
  • items.appendModel(applications); = Applications in the Launcher
  • items.appendModel(workspaces); = Workspaces Icon
  • items.appendModel(devices); = Mounted Devices
  • shelfItems.appendModel(trashes); = Trash Icon
Remove the any of those lines to remove its corresponding Launcher item.

You can also rearrange those lines to rearrange the corresponding Launcher items. Notice that items specified as 'shelfItems' will always end up at the bottom of the Launcher, with the leading space you know from the Trash Icon. But you can also simply specify all items as 'items', thus lining them all up in a row, without any spaces!

Change Launcher Background

To change the background color or opacity (transparency) of the Launcher background, you need to edit the 'Launcher.qml' under the '/usr/share/unity-2d' directory. But before, back it up as described above.

gksudo gedit /usr/share/unity-2d/launcher/Launcher.qml

Find this section:

Rectangle {
    Accessible.name: "background"
    anchors.fill: parent
    color: "black"
    opacity: 0.66
    visible: screen.isCompositingManagerRunning
}

For 'color', you can use color names or hex values, formatted like "#00000", for example.

Disable Backlight of Launcher Items

To disable the backlight of the Launcher items, you need to edit the 'LauncherItem.qml' under the '/usr/share/unity-2d' directory. But before, back it up as described above.

gksudo gedit /usr/share/unity-2d/launcher/LauncherItem.qml

Find this section, and outcomment it like so:

/* Image {
    id: tileBackground
    property color color: defaultBackgroundColor
    anchors.fill: parent
    smooth: true

    SequentialAnimation on opacity {
    NumberAnimation { to: 0.0; duration: 1000; easing.type: Easing.InOutQuad }
    NumberAnimation { to: 1.0; duration: 1000; easing.type: Easing.InOutQuad }

        loops: Animation.Infinite
        alwaysRunToEnd: true
        running: launching
    }

    sourceSize.width: item.tileSize
    sourceSize.height: item.tileSize
    source: {
        var actualColor = launcherView.focus && item.activeFocus ? selectedBackgroundColor : color
        return "image://blended/%1color=%2alpha=%3"
            .arg("artwork/round_corner_54x54.png")
            .arg(actualColor.toString().replace("#", ""))
            .arg(1.0)
    }
} */

Change Launcher Border

To decrease or increase the width of the Launcher border, you need to edit the 'Launcher.qml' under the '/usr/share/unity-2d' directory. But before, back it up as described above.

gksudo gedit /usr/share/unity-2d/launcher/Launcher.qml

Find this section, and change the value for 'width' to your liking:

Image {
    Accessible.name: "border"
    id: border

    width: 1
    height: parent.height
    anchors.right: parent.right
    fillMode: Image.TileVertically
    source: "artwork/background.png"
}

To change the color of the Launcher border, you need to replace the file 'background.png' under '/usr/share/unity-2d/launcher/artwork'. After backing it up as described above, you can place your desired 'background.png' on your desktop, and run these commands to copy it over there and set the right permissions:

sudo cp ~/Desktop/background.png /usr/share/unity-2d/launcher/artwork/background.png
sudo chmod 644 /usr/share/unity-2d/launcher/artwork/background.png

Related Posts:

Unity , Unity 2D