Difference between revisions of "Hacking:Code Snippets/Miscellaneous"

From GIMP Developer Wiki
Jump to: navigation, search
(add 'Determining compiler')
 
(add 'Determining modifiers of keyboard events (Ctrl, Alt, etc.)')
Line 19: Line 19:
  
 
[http://sourceforge.net/p/predef/wiki/Home/ Pre-defined Compiler Macros page at Sourceforge.net]
 
[http://sourceforge.net/p/predef/wiki/Home/ Pre-defined Compiler Macros page at Sourceforge.net]
 +
 +
=Determining modifiers of keyboard events (Ctrl, Alt, etc.)=
 +
 +
<pre>
 +
#include <gdk/gdkkeysyms.h>
 +
 +
my_key_event_handler(const GdkEventKey *keyevent)
 +
{
 +
 +
/* check for Ctrl (also on OS X; do not confuse with Cmd there!): */
 +
if (keyevent->state & GDK_CONTROL_MASK)
 +
 +
/* check for Alt: */
 +
if (keyevent->state & GDK_MOD1_MASK)
 +
 +
}
 +
</pre>

Revision as of 18:26, 12 April 2014

Determining compiler

To make use of GCC specific features, use the __GNUC__ macro:

#ifdef __GNUC__
...
#endif

You can also grep the code for __GNU to find out existing samples to learn from.

To make use of LLVM/Clang specific features, use the Clang language extensions.


See also:

Common predefined macros in GCC

Pre-defined Compiler Macros page at Sourceforge.net

Determining modifiers of keyboard events (Ctrl, Alt, etc.)

#include <gdk/gdkkeysyms.h>

my_key_event_handler(const GdkEventKey *keyevent)
{

/* check for Ctrl (also on OS X; do not confuse with Cmd there!): */
if (keyevent->state & GDK_CONTROL_MASK)

/* check for Alt: */
if (keyevent->state & GDK_MOD1_MASK)

}