Archive

Archive for January, 2014

CoreGTK

January 28th, 2014 2 comments

A while back I made it my goal to put together an open source project as my way of contributing back to the community. Well fast forward a couple of months and my hobby project is finally ready to be shown the light of day. I give you… CoreGTK

CoreGTK is an Objective-C binding for the GTK+ library which wraps all objects descending from GtkWidget (plus a few others here and there). Like other “core” Objective-C libraries it is designed to be a very thin wrapper, so that anyone familiar with the C version of GTK+ should be able to pick it up easily.

However the real goal of CoreGTK is not to replace the C implementation for every day use but instead to allow developers to more easily code GTK+ interfaces using Objective-C. This could be especially useful if a developer already has a program, say one they are developing for the Mac, and they want to port it to Linux or Windows. With a little bit of MVC a savvy developer would only need to re-write the GUI portion of their application in CoreGTK.

So what does a CoreGTK application look like? Pretty much like a normal Objective-C program:

/*
 * Objective-C imports
 */
#import <Foundation/Foundation.h>
#import "CGTK.h"
#import "CGTKButton.h"
#import "CGTKSignalConnector.h"
#import "CGTKWindow.h"

/*
 * C imports
 */
#import <gtk/gtk.h>

@interface HelloWorld : NSObject
/* This is a callback function. The data arguments are ignored
 * in this example. More callbacks below. */
+(void)hello;

/* Another callback */
+(void)destroy;
@end

@implementation HelloWorld
int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    /* We could use also CGTKWidget here instead */
    CGTKWindow *window;
    CGTKButton *button;

    /* This is called in all GTK applications. Arguments are parsed
    * from the command line and are returned to the application. */
    [CGTK autoInitWithArgc:argc andArgv:argv];

    /* Create a new window */
    window = [[CGTKWindow alloc] initWithGtkWindowType:GTK_WINDOW_TOPLEVEL];

    /* Here we connect the "destroy" event to a signal handler in 
     * the HelloWorld class */
    [CGTKSignalConnector connectGpointer:[window WIDGET] 
        withSignal:@"destroy" toTarget:[HelloWorld class] 
        withSelector:@selector(destroy) andData:NULL];

    /* Sets the border width of the window */
    [window setBorderWidth: [NSNumber numberWithInt:10]];

    /* Creates a new button with the label "Hello World" */
    button = [[CGTKButton alloc] initWithLabel:@"Hello World"];

    /* When the button receives the "clicked" signal, it will call the
     * function hello() in the HelloWorld class (below) */
    [CGTKSignalConnector connectGpointer:[button WIDGET] 
        withSignal:@"clicked" toTarget:[HelloWorld class] 
        withSelector:@selector(hello) andData:NULL];

    /* This packs the button into the window (a gtk container) */
    [window add:button];

    /* The final step is to display this newly created widget */
    [button show];

    /* and the window */
    [window show];

    /* All GTK applications must have a [CGTK main] call. Control ends here
     * and waits for an event to occur (like a key press or
     * mouse event). */
    [CGTK main];

    [pool release];

    return 0;
}

+(void)hello
{
    NSLog(@"Hello World");
}

+(void)destroy
{
    [CGTK mainQuit];
}
@end
Hello World in action

Hello World in action

And because Objective-C is completely compatible with regular old C code there is nothing stopping you from simply extracting the GTK+ objects and using them like normal.

// Use it as an Objective-C CoreGTK object!
CGTKWindow *cWindow = [[CGTKWindow alloc] 
    initWithGtkWindowType:GTK_WINDOW_TOPLEVEL];

// Or as a C GTK+ window!
GtkWindow *gWindow = [cWindow WINDOW];

// Or even as a C GtkWidget!
GtkWidget *gWidget = [cWindow WIDGET];

// This...
[cWindow show];

// ...is the same as this:
gtk_widget_show([cWindow WIDGET]);

You can even use a UI builder like GLADE, import the XML and wire up the signals to Objective-C instance and class methods.

CGTKBuilder *builder = [[CGTKBuilder alloc] init];
if(![builder addFromFile:@"test.glade"])
{
    NSLog(@"Error loading GUI file");
    return 1;
}

[CGTKBuilder setDebug:YES];

NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:
                 [CGTKCallbackData withObject:[CGTK class] 
                     andSEL:@selector(mainQuit)], @"endMainLoop",
                 [CGTKCallbackData withObject:[HelloWorld class] 
                     andSEL:@selector(hello)], @"on_button2_clicked",
                 [CGTKCallbackData withObject:[HelloWorld class] 
                     andSEL:@selector(hello)], @"on_button1_activate",
                 nil];

[builder connectSignalsToObjects:dic];

CGTKWidget *w = [builder getWidgetWithName:@"window1"];
if(w != nil)
{
    [w showAll];
}

[builder release];

So there you have it that’s CoreGTK in a nutshell.

There are a variety of ways to help me out with this project if you are so inclined to do so. The first task is probably just to get familiar with it. Download CoreGTK from the GitHub project page and play around with it. If you find a bug (very likely) please create an issue for it.

Another easy way to get familiar with CoreGTK is to help write/fix documentation – a lot of which is written in the source code itself. Sadly most of the current documentation simply states which underlying GTK+ function is called and so it could be cleaned up quite a bit.

At the moment there really isn’t anything more formal than that in place but of course code contributions would also be welcome!

Update: added some pictures of the same program running on all three operating systems.

Hello World on Windows

Hello World on Windows

Hello World on Mac

Hello World on Mac

Hello World on Linux

Hello World on Linux

This post originally appeared on my personal website here.




I am currently running a variety of distributions, primarily Linux Mint 17.
Previously I was running KDE 4.3.3 on top of Fedora 11 (for the first experiment) and KDE 4.6.5 on top of Gentoo (for the second experiment).
Check out my profile for more information.

A tale of a gillion installs

January 21st, 2014 1 comment

Install number one: LMDE 201303.  I was hoping for the best of both worlds, but I got driver issues instead.  LMDE has known ATI proprietary driver install issues.  I followed the Mint instructions and got it working, then got a blank screen after too much tinkering.  I was surprised that LMDE had this problem since Debian doesn’t, and LMDE should be a more polished version of LMDE.  This wasn’t a big deal, but I decided to give Debian a chance.

Install number two: debian stable (7.3).  The debian website has a convoluted maze of installation links, but it’s still fairly easy to find an ISO for the stable version you need.  I installed from the live ISO using a USB key.  The installation and ATI driver update went smoothly, and I thought all was well at first.  I soon realized that about 50% of reboots failed; the audio driver was the culprit.  I installed the latest driver from Realtec/ALSA and it sort of worked, but I was still getting some crap from # dmesg and the audio would crackle with some files.

LMDE.  I live booted LMDE to see if the same issue existed there and it did.

Time for Mint 16.  As expected everything worked.  Man I really wish Ubuntu hadn’t chosen the dark side – their OS is really good.  All of these distros use ALSA audio drivers, so why is Ubuntu the only one that works?   Kernel versions:

debian stable (7.3):
cat /proc/asound/version
Advanced Linux Sound Architecture Driver Version 1.0.24.
Mint 16:
cat /proc/asound/version
Advanced Linux Sound Architecture Driver Version k3.11.0-12-generic.

One more thing to check.  What kernel version is the real debian testing “jessie” using:

http://packages.debian.org/testing/kernel/linux-image-3.12-1-amd64

LMDE 201303 = 3.2
debian stable 7.3 = 3.2
Mint 16 = 3.11
debian testing “jessie - Jan 2014” = 3.12!

I determined to try debian testing before settling for Mint.  I tried a netinstall from USB key which killed my PC and grub bootloader.  The debian stable live iso usb key decided to stop working as well.   I finally got a real DVD debian stable install to work, changed the repositories to point to “jessie” and upgraded.  I was very surprised to see this worked!   I’m having some problems with bash, but all of my day to day software is up and running.  Nice.

TL;DR: LMDE was using an old kernel so I needed the real debian testing (jessie) to solve my driver problems.

So many flavours – with bonus privacy rant!

January 21st, 2014 1 comment

It’s interesting reading the old Linux Experiment first posts when people were contemplating which distro to install.  It’s been 4.5 years since then and the linux world has evolved.  Most noticeable, was no one talking about Mint!

I was considering three distros for my home PC dual boot:

  1. Debian
  2. LMDE
  3. Mint

I wanted something in the debian family since it seems to be receiving, by far, the most attention.  I expect this also means it gets the most activity and updates.  Ubuntu would probably work the best out of the box, but as you probably already know:

https://en.wikipedia.org/wiki/Unity_%28user_interface%29#Privacy_controversy

Ubuntu’s privacy issues are a deal breaker of course, but they also made me question Mint.  I don’t want to support Ubuntu and I think using Mint would indirectly do that.  Also, Mint does have some minor default search engine sketchyness going on.   I realize that these developers need funding, but I don’t think selling their users’ stats or useage is the way to do it.  I think donations are the way to go and they seem to be working for Wikimedia.  Developing non-essential non-related commercial software in parallel with the OS might be another alternative… hmm, sounds like a slippery slope.

The plan was: Try LMDE first, Debian stable if more stability is needed, and Mint if I got to the point that I just wanted things to work.  Results to follow!

TL;DR:  I planned to install LMDE or Debian, since Ubuntu wants to track me.

Screen brightness work around (part 2)

January 19th, 2014 No comments

As mentioned before I am having some issues with my laptop’s hardware and controlling the screen brightness. Previously my work around was to set acpi_backlight=vender in the grub command line options. While this resulted in having full screen brightness it also removed my ability to use my keyboard function keys to adjust the screen brightness on the fly (not so good when you’re on battery). Removing this option allowed me to manually adjusted my screen brightness again but once again always started the laptop at zero brightness. What to do?

While far from a perfect solution my current work around is to use xdotool to simulate key presses on login which raise the screen brightness for me automatically. Here is the script that I run on startup:

#!/bin/bash
for i in {1..20}
do
     xdotool key XF86MonBrightnessUp
done

While this works great it still isn’t perfect. Because xdotool requires an X session it means I cannot run it before one is created. If you were unaware the login screen, in my case MDM, does not run inside of X (it actually starts X when you successfully login). So while this will automatically brighten my screen it won’t do so until I type in my username and password, leaving me to type into a fully dark screen or manually adjust the brightness up enough to see what I’m doing. Hopefully I’ll have a better solution sooner rather than later…




I am currently running a variety of distributions, primarily Linux Mint 17.
Previously I was running KDE 4.3.3 on top of Fedora 11 (for the first experiment) and KDE 4.6.5 on top of Gentoo (for the second experiment).
Check out my profile for more information.

Initial thoughts about PC-BSD

January 16th, 2014 No comments

[Please note: this is a historical post - I'm no longer running *BSD in 2014, and this is a collection of thoughts on its setup in case I decide to return to the operating system. Further posts from me will focus on other Linux experiences.]

So after not too much effort, I’ve gotten PC-BSD to replace my FreeBSD installation and am back up and running. Some minor tips, interesting facts and tweaks:

  • Default filesystem and mountpoints all seem to be ZFS, which would make PC-BSD probably the quickest and easiest way to get a functional desktop environment running with this neat filesystem.
  • To enable Flash playback in Chromium (and I assume Firefox), run
    flashpluginctl on

    from the terminal (under your own user account, not root) and restart the browser. Thanks to the PC-BSD forums for this answer.

  • Enabling SSH server: add sshd_enable=”YES” to /etc/rc.conf, then /etc/rc.d/sshd start. You’ll also need to allow TCP port 22 inbound through the firewall in the PC-BSD Control Panel/Networking/Firewall Manager application.
  • Sound worked out of the box without any driver finagling, and is a much more simplistic setup:

 

From the PC-BSD Control Panel, a very simple way to select the default sound device.

From the PC-BSD Control Panel, a very simple way to select the default sound device.

I’m assuming the situation would have been better than the Kubuntu trials and tribulations with PulseAudio - all the possible nVidia HDMI output ports are listed in this dropdown list, as well as my onboard sound and USB/stereo audio adapter. In Phonon, the list is much simpler:

No greyed-out cards or shenanigans - Phonon just shows the default sound card from PC-BSD.

No greyed-out cards or “missing sink”s – Phonon just shows the default sound card from PC-BSD.

 

So far this has been a pretty great introductory experience – the desktop is polished, KDE integration appears to work well, and manual configuration has been limited to what I’d consider more advanced functionality like the SSH daemon.




I am currently running various *BSD variants for this Experiment.
I currently run a mix of Windows, OS X and Linux systems for both work and personal use.
For Linux, I prefer Ubuntu LTS releases without Unity and still keep Windows 7 around for gaming.
Check out my profile for more information.
Categories: Flash, Jake B, PC-BSD Tags: , ,

What up? (First Post)

January 16th, 2014 No comments

My first post here – starting a linux experiment:

First of all, I would like to thank Tyler B for helping me get started by patiently answering my level 0 linux questions.

I’ve installed linux several times in the last ten years, sometimes for fun, but usually when required for school.  I’ve even developed a linux app complete with a GUI and DB integration.  But even with all this exposure to linux I’ve managed to learn very little about it.  How is that possible?  Well, if you stick to pre-configured dev environments with working tools, avoiding learning about the OS is easy.

My new project has a different motivation.  Rather than using Linux to complete a project, using Linux is the project.  I want to understand how linux works and I think the best way to start is to “learn by doing”.  My plan is to use linux on my main home computer for everything except Windows gaming, which is rare for me anyways.  I would then like to move on to LFS.

TL;DR: I’m going to install and learn about linux.

Categories: Greg W, Linux Tags: