Category: Whisker Menu (Page 7 of 8)

Revisiting signal handlers

Posted on November 24, 2013, under Programming, Whisker Menu

Ever since I changed how I handle connecting GTK+ signals to C++ members I have never been completely happy with that code. I prefer to not repeat myself, and I like the power and simplicity that templates can bring (and the safety they have over macros). I thought that any GCC before 4.7 would not allow me to write the signal handlers the way I want, but it turns out I was wrong!

Based on the load time error of Whisker Menu 1.0.0 I had surmised that there was a bug in GCC where you can’t take the address of a template function because it did not handle the name mangling properly. However, upon further research I discovered that the bug really is that if you take the address of a template function and cast it to something else before storing it the template is not instantiated. Easy enough to fix: just create a function pointer of the correct type and then cast that:

template <typename T, typename R, typename A1, typename A2>
gulong g_signal_connect_slot(gpointer instance,
		const gchar* detailed_signal,
		R (T::*member)(A1,A2),
		T* obj,
		bool after = false)
{
	class Slot
	{
		T* m_instance;
		R (T::*m_member)(A1,A2);

	public:
		Slot(T* instance, R (T::*member)(A1,A2)) :
			m_instance(instance),
			m_member(member)
		{
		}

		static R invoke(A1 a1, A2 a2, Slot* slot)
		{
			return (slot->m_instance->*slot->m_member)(a1, a2);
		}

		static void destroy(Slot* slot)
		{
			delete slot;
		}
	};
	R (*invoke_slot)(A1,A2,Slot*) = &Slot::invoke;
	void (*destroy_slot)(Slot*) = &Slot::destroy;

	return g_signal_connect_data(instance,
			detailed_signal,
			reinterpret_cast<GCallback>(invoke_slot),
			new Slot(obj, member),
			reinterpret_cast<GClosureNotify>(destroy_slot),
			after ? G_CONNECT_AFTER : GConnectFlags(0));
}

class Example
{
public:
	Example();
	gboolean button_press_event(GtkWidget* widget, GdkEventButton* event);
};

Example::Example()
{
	g_signal_connect_slot(widget, "button-press-event", &Example::button_press_event, this);
}

The code is not quite as simple as the original version, though, because variadic templates are only available in C++11. Instead I have to make make overloads of the function for each amount of parameters I want to support. I did clean it up in other ways by using local classes, which I think makes the new template slot handlers more clear. It even compiles to less space than using class functions for slots.

I’m sorry to disappoint the users who have been requesting this, but after giving it some serious consideration I have decided that I will not be porting Whisker Menu to any other desktop environment. I set out to make a menu for Xfce, and Whisker Menu relies on Xfce quite a lot throughout the codebase. I would have to redesign Whisker Menu to try and support different environments, and even then I would still have to completely rewrite it for some of them as they are Qt based and very little code could be shared between them. Again, sorry, but Whisker Menu will remain Xfce only.

A new Whisker Menu release

Posted on October 29, 2013, under Whisker Menu

I have released version 1.2.0 of Whisker Menu. This release contains several smaller but commonly requested features. For those users who wanted subcategories you can now enable loading the menu hierarchy, which will show each category as a tree instead of a flat list. You can also tweak the layout of the menu to be similar to Windows by placing the search entry next to the panel button. Additionally, you can also choose which commands are run when you press the “All Settings”, “Lock Screen”, and “Log Out” buttons. Enjoy!

Whisker Menu 1.1.0 released!

Posted on July 25, 2013, under Whisker Menu

23 comments

I have made a new stable release of Whisker Menu, version 1.1.0. This release includes the three most commonly requested features: the ability to show the menu from an external command (which allows for showing the menu from a keyboard shortcut), the ability to have text on the panel button, and finally the ability to switch the categories by hovering for a small time over the category buttons instead of having to click on them.

Another big feature in this release is that I rewrote the search algorithm inspired by that of the Synapse semantic launcher. Whisker Menu will now also search for words and each character instead of just finding exact matches of the text you typed. This allows you to type ff and find both LibreOffice and Firefox. The search results are also now sorted by relevance to make it easier to find what you are looking for. And finally, it now also searches the names of the executables (so you can for example find GNOME’s Document Viewer by searching for evince, as that is the program’s name).

I hope you enjoy this update to the menu! As always, please let me know if you have any issues.

Go, little menu!

Posted on July 19, 2013, under Whisker Menu

16 comments

I am really excited and pleased with how popular Whisker Menu is turning out to be! It has already been added to some Linux distros, and both Manjaro and the Xfce edition of Linux Mint have made it the default menu! That is amazing, and I still can’t believe it. Thank you to all of those who have spread the word, reported bugs, and submitted translations!

Categories