Craig Small: Context sensitive menus with GtkTreeView
A project I now maintain called GJay uses the GTK+ toolkit and has a GtkTreeView that shows the directories and the songs in them. I was wanting to add a context sensitive menu on that view so that you could do things to the item you have right-clicked on; generally file specific things like give me information about this song or queue it to play. My only problem was, how to do it? A few Google searches showed things that were almost, but not quite, what I was after. The main problem being either the documentation was incomplete or it assumed I was after the selected field (the row I may of left-clicked on) and not the one I right-clicked on to get this event.
This GtkTreeView uses a store where NAME_COLUMN is defined at 0, meaning it is the first column. The program uses this column to store the filename of the song.
So first I needed to create an event to kick things off, we need to connect the button-press-event to our tree_view, which calls a function in this case view_on_button_pressed.
So a breakdown of what my callback is doing:
Related articles
g_signal_connect(tree_view, "button-press-event", G_CALLBACK(view_on_button_pressed), NULL);
gboolean view_on_button_pressed(GtkWidget *tree_view, GdkEventButton *event, gpointer user_data) GtkTreeSelection *selection; GtkTreePath *tree_path; GtkTreeModel *tree_model; GtkTreeIter tree_iter; gchar *name; if (event->type == GDK_BUTTON_PRESS && event->button == 3) tree_model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree_view)); if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tree_view), (int)event->x, (int)event->y, &tree_path, NULL, NULL, NULL)) if (gtk_tree_model_get_iter(tree_model, &tree_iter, tree_path)) gtk_tree_model_get(tree_model, &tree_iter, NAME_COLUMN, &name, -1); g_print("rc name is %s\n", name);
- Line 1:The callback s widget is the GtkTreeView widget we connected the signal with
- Line 10:Checks the event was a button press and button #3 (right button)
- Line 11: Find the GtkTreeModel from the given GtkTreeView
- Lines 12-14: Get the GtkTreePath that the right-click was sitting at by using the event coordinates.
- Line 15: Convert the GtkTreePath into a GtkTreeIter
- Line 16: Find the actual value we put into this row.
First things first: The issue with the feedback form is fixed. Sorry for the inconvenience.
I'm not sure if you followed
I ve been working on a replacement to
So, it's now over.
After two weeks of DebCamp+DebConf, followed by two weeks touring over
to the best places in Nicaragua with my beloved Elisabeth (our first
long holidays as a couple without children since....1987!), my
best holidays EVER are over.
I visited a wonderful country. I met wonderful people. And I have to
come back as I left un unachieved volcano climb (some could think I
did that on purpose just to have an excuse for coming back)...:-)
I'll probably try to blog about all this in a soon-to-come very long
bubullish post (IOW: full of typos and Frenglish) for those of you who
aren't tired of these.
Now, doh, I have two gardens to clean out before resuming work in less
than two weeks.
So this week I bought a cheap Android tablet, specifically to allow me to read books upon the move and listen to music at home.
Currently my desktop PC has a bunch of music on it, and I listen to it locally only. In my living room I have an iPOD in a dock which has identical contents.
In my bedroom? No music. This was something I wished to change.
The music on my desktop is played via
A copy of this post is sent to
This screencast shows what I built. Scroll down for my Yesod braindump.
<video controls="controls" src="http://joeyh.name/screencasts/git-annex-webapp.ogg"></video>
during the last weeks I was quite busy with other things (like DebCamp,
DebConf, & vacations), so this is a report covering 4 weeks. at
least I managed to catch up during the last days a bit
I'm forty pages into a battered copy of "Complicity" by Iain Banks. I picked
this copy up for the princely sum of 90p at Barter Books last weekend. For the
uninitiated, Barter Books is a grand old bookshop situated in a disused train
station in Alnwick, Northumberland. It has the dubious pleasure of being the
originator of the "keep calm and carry on" fad.
At the time that I bought it, I wasn't sure whether it was already in my
swollen reading pile, but 90p wasn't a great loss if so. I could leave it
in the book pile at my next hotel. (it was, and that's a sorry indictment of
the state of my reading pile.)
This gnarled paperback has character. There's a faded price sticker on the
back revealing a first-hand price in Australian Dollars. The book started its
post-sale life on the other side of the world. Where else has it been? I take
some small pleasure in planning the next step in its future.
To imagine this book with a long tail of readers having a free market value of
90p, or roughly the price of a posh chocolate bar, I'm struck by both wondering
how publishers and writers like Mr Banks make a living (and yet they do) but
also how the pricing of ebooks, completely lacking in this character I've
written about and non-transferable, seems over inflated to the end user.
I've been struggling to short list a selection of books to take on holiday.
Most of my friends have responded "buy a kindle", with a complete lack of
sympathy for my predicament. I'm borrowing one which means I can finally find
out whether I'll "take" to it. I'm concerned I'll not be able to get sucked
into a story in the same way I can with a paper book. I certainly won't rely on
just the kindle for my reading needs.
I don't want to prejudge my experiment too much but I suspect I won't be
convinced. Where I can see technology supporting my reading is in addition to
the paper book: particularly for non fiction, technical books, academic papers,
more graphical-oriented things (photo books, graphic novels). I do have a small
but growing collection of old, rare-in-print texts that I've only been able to
source as PDFs. I think something like the Google Nexus 7 would do the job for
these and fit into my life more readily than the kindle.
Playing around with LLC controls on Sandybridge today.
What I wanted to know was how caching backbuffers affects application
performance. The reason for this question is that when the driver uses
page flipping to display a new frame, we force the new scanout buffer
to be uncached because the display hardware only scans out from main
memory. However, when we go back to using this buffer as the next
back-buffer, we don t turn the caching bits back on as that requires
writing GTT entries to change caching modes.
This means that swapping via page-flipping and swapping via copying
has a large change in main memory access patterns during rendering
page flipping applications use an uncached back buffer while copying
applications use a cached back buffer.
What effect does the back-buffer caching-mode have on application
performance?
The changes
In the kernel, I have three modes
1) Existing code. Set buffer objects to cache mode none when
preparing them as scanout buffers. The first time the application
flips to a back buffer, caching is disabled on that buffer forever
2) Flip back and forth. Set buffers to cache mode none when used
as scanout. When that stops, flip them back to cache mode llc.
This involves a whole lot of clflushing and GTT rewriting, obviously.
3) Flush to memory, but don t disable caching. In this mode, the
buffer gets flushed (from both CPU and GPU) before being used as a
scanout, but the cache mode isn t changed.
Benchmarking with glxgears
The first test was pretty simple I hacked up glxgears (yes,
glxgears is not a benchmark) to redraw the same frame multiple times
(including the clear) per swap to provide a scalable amount of
work per swap. No pixel operations, so this is just writing to the
back buffer. Thes numbers are the median of 5 runs, except for those
obviously limited by the refresh rate.
This is one of the days where reading my everyday newspaper was worth more than just getting bitter at the news. I found