How to tell if you are running Eclipse on Gtk2 or on Gtk3

When troubleshooting Eclipse bugs, I sometimes ask if you are running eclipse on gtk2 or gtk3.

Usually I can tell visually if Eclipse is running on Gtk2 or Gtk3, but this changes depending on your system theme.

In the about section

As Alexander Kurtakov pointed out and described in Lar’s article ,

Help -> About -> Installation Details -> Configuration Tab.

Look for something like:
org.eclipse.swt.internal.gtk.version=3.14.12

It’s usually somewhere near line 84 ish. But you can copy the text and search for it in your text editor.

Note, if this line is missing altogether, you’re (very most likely) running Eclipse on Gtk2.

See what version is on your system

You can find out which version of gtk is installed on your system by running pkg-config (you might need to install it first). This gives you an indication of which version of gtk eclipse might be using.

pkg-config --modversion gtk+-3.0

Force Eclipse to use either gtk2 / gtk3

You can force Eclipse to use a certain version of gtk:

#Gtk3 forced:
export SWT_GTK3=1
eclipse

#Gtk2 forced:
export SWT_GTK3=0
eclipse

Under gtk3, the entry in the about section should be present like: org.eclipse.swt.internal.gtk.version=3.14.12

 

[edit 2016-09Sep-08Thu]
This is actually by far the most visited blog entry on my blog (20k+ views)
I reference this page quite often, I made a short/memorable url for it: http://bit.ly/gtk2orgtk3

Correct SWT code style for widget development and using Eclipse’s regex to fix your code style.

When doing SWT Development, if you submit code with the wrong style, you might get some code-comments from other contributors advising you to fix your style.

Luckily there is an Eclipse-SWT-formatted profile that one can use or one can fix them with some Regex.

Note: I will update this article as I find out more about SWT style.
Continue reading

How to create cross-platform SWT applications packaged in a single jar in Eclipse

The deal with SWT is that you geneally create a jar that runs nativley on a single platform.

This means that if you want to create an application that works on windows/mac/linux in both 32/64 bit, then you need to compile/package jar 6 files and distribute one file per platform.

This is very cumbersome for small projects where you want a single file that runs on every platform.

The solution is to bundle the jars and load them dynamically with Mchr3k’s SWT Jar loader.

The next challenge is how to get this business working in Eclipse. Well, there is a guide for this.

Basically, you create a project with the name “HelloWorld”, you have to
download the swt jar’s and rename them to match os/version and then you
have to add a build.xml file. This takes about 30 minutes.

I followed the guide and actually got it to work.

To make life easier, I created a git-repo with a template project.  You can clone it and start a SWT project with that.

I used swt 4.4 in the project. In the future you might want to update it. To do so:

  • Download the latest jar files from Eclipse’s download site .
    • click on the most recent version, e.g ‘4’4,
    • then search for “SWT Binary and Source”
    • download the Windows 32/64 Versions,   linux x86/x86_64/GTK+ versions, Mac OS X versions
    • open the archives and extract the ‘swt.jar’ files
    • match the jar files to the jar files in the project ./gui folder. But append new version. (4.4 -> 4.x)
  • Edit the build.xml file,
    • change the “swtversion=”4.4″” to the newer version.
    • Also update <fileset dir=”./gui” includes=”swt-*-4.4.jar” />

Screen shots:

Linux

crossSwt1

You can run the generated jar file with ‘java -jar crossSWT.jar”:

crossSWT jar

OS X

Here I had to launch the jar with a special paramater:
java -jar -XstartOnFirstThread crossSWT.jar
os x

Windows

I don’t use windows :-), but rumors has it works on windows also.

How to compile various gtk3 versions and run eclipse Apps with those (for SWT Widget testing)

ScreenShot_2014_09_29__15_07_28_

When developing SWT widgets, we need to test them on various GTK versions to ensure backwards compatibility.

There are some tricks and perks involved.

Get Gtk sources

  • Go to the gtk git repo and pull the code: https://git.gnome.org/browse/gtk+/
    (I recommend the https version: https://git.gnome.org/browse/gtk+)
    (if you don’t know how to use eclipse’s EGit, read this)
  • Check out the versions that you’re interested in (e.g 2.24, 3.10, 3.4, 3.8)
    These are found in major Linux distributions (e.g ubuntu 12..).
  • For the time being, check out the newest gtk version (e.g 3.10 at the time of writing).
    (It’s easier to build a newer version than an older one)
  • Open Terminal, go to your checked out gtk branch.
    Run the following commands:

    ./autogen.sh
    ./configure --enable-x11-backend --enable-wayland-backend
    make
    
  • The first time you run the commands, you might run into errors telling you you’re missing something on your system. Inspect autogen.sh to see what it runs and then install the utilities with yum.
  • Now copy gtk to another place on your system. E.g ~/src/gtk2_24 This way you don’t have to recompile this business every time.
  • Now you can build the other versions and similarly copy them to ~/src/gtk*_*
  • NOTE ON gtk3.4 (and maybe older) The Wayland configuration makes certain things look more correct. But sometimes it makes building older versions (like gtk3.4) near impossible due to missing dependencies. In this case, run the configure without these:
     ./autogen.sh ./configure make 

Configure Eclipse to use the gtk you compiled

  • Edit your run-configuration of the code snippet that you want to run.
  • Navigate to “Environmental Variables”
  • Click on “Add”, type in:
    name: LD_LIBRARY_PATH
    path: #your_compiled_gtk      //e.g /home/lufimtse/src/gtk3_10/gtk/.libs
  • Name your configuration (I reccomend appending gtk version, e.g “ControlExample (g3-10)”)
  • It should look something like this:
    Eclipse env var
  • Now run the configuration and you should see your application rendered in gtk*.*.
    You may note that it won’t have any styling:
    java app in compiled gtk
  • The lack of styling is due to the fact that there is no theaming.
    Now sometimes you might want the compiled gtk to use your system theame to see impact of themes on looks.
    To do so, do as above except run the configuration as following:

    ./configure --prefix=/usr --sysconfdir=/etc --enable-broadway-backend --enable-x11-backend --disable-wayland-backend
    

    In the interest of comparison: (left native look, right bare look)
    native vs bare

  • Lastly, in your source code, you might want to verify that you’re running the compiled gtk and not your own. Use this line of code:
    System.out.println("GTK Version: " + OS.gtk_major_version() + "." + OS.gtk_minor_version() + "." + OS.gtk_micro_version());

     

pipe commands into clipboard

I often need to pipe commands into the clipboard. E.g when I type “pwd” to get the present working directory, I would normally select the line and then copy it into my clipboard.

After a while this became tedious so I wrote a script to make life easier. I created a bash script called “toclip”…

Continue reading

Create an area screenshot, host it on github and copy web url to clipboard with one command

I often find myself having to create a screenshot and upload it somewhere so that I can paste it on irc/(mail without adding weight to email)/bugzilla etc.

Eventually I solved the problem by writing  a script that:

  1. Creates a screenshot of an area (gnome-screenshot)
  2. Saves it to your picture folder
  3. adds/commits/pushes to your git hub
  4. copies path to your clipboard
  5. opens chrome to verify that screenshot uploaded successfully.

….

Continue reading