diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0deb99651914b170d67b2efbdb11e0f2bd3e15c0..a3621bdbaf70c7e5a9166a4e66018c979606cbea 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -955,6 +955,11 @@ if(DLFCN_H)
   list(APPEND EXTERNAL_LIBRARIES ${CMAKE_DL_LIBS})
 endif(DLFCN_H)
 
+check_include_file(linux/joystick.h LINUX_JOYSTICK_H)
+if(LINUX_JOYSTICK_H)
+  set_config_option(HAVE_LINUX_JOYSTICK "LinuxJoystick")
+endif(LINUX_JOYSTICK_H)
+
 if(MSVC)
   add_definitions(-D_USE_MATH_DEFINES -DNOMINMAX 
                   -D_CRT_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_DEPRECATE)
diff --git a/Common/GamePad.cpp b/Common/GamePad.cpp
index 7e1ce448b53664f67841722ba641802337f95f5b..ae5f5ceb4f5a87a9bf4ad9f7924750162b2a6fc6 100644
--- a/Common/GamePad.cpp
+++ b/Common/GamePad.cpp
@@ -54,7 +54,6 @@
 #include <iostream>
 #include <stdio.h>
 #include "GamePad.h"
-#include "Context.h"
 
 #if !defined(WIN32)
 #include <unistd.h>
@@ -105,11 +104,7 @@ GamePad::GamePad() : active(false), frequency(.01), gamepad_fd(0)
   for(int i = 0; i < axes; i++) axe[i] = 0;
   joyGetPosEx(gamepad_fd, &infoex);
   infoex.dwFlags = JOY_RETURNALL;
-#elif defined(__APPLE__)
-
-  // ??
-
-#else // LINUX
+#elif defined(HAVE_LINUX_JOYSTICK)
   gamepad_fd = open(GAMEPAD_DEV, O_RDONLY | O_NONBLOCK);
   if (gamepad_fd > 0) {
     ioctl(gamepad_fd, JSIOCGNAME(256), name);
@@ -141,7 +136,7 @@ GamePad::~GamePad()
 {
   active = false;
   gamepad_fd = 0;
-#if !defined(WIN32) && !defined(__APPLE__)
+#if defined(HAVE_LINUX_JOYSTICK)
   close(gamepad_fd);
 #endif
 }
@@ -199,11 +194,7 @@ int GamePad::read_event()
     std::cout<< infoex.dwButtonNumber << std::endl;
     std::cout<< infoex.dwPOV << std::endl;
   */
-#elif defined(__APPLE__)
-
-  // ??
-
-#else // LINUX
+#elif defined(HAVE_LINUX_JOYSTICK)
   int result = read(gamepad_fd, &event, sizeof(event));
   if (result > 0){
     switch (event.type){
@@ -232,18 +223,18 @@ int GamePad::read_event()
 
 void GamePad::affiche()
 {
-  for (int i = 0; i < 6; i++) std::cout<<("_________");
-  std::cout<<std::endl; std::cout<<"  axis ";
-  for (int i = 0; i < 6; i++) std::cout<<" | "<<i;
-  std::cout<<std::endl;  std::cout<<"       ";
-  for (int i = 0; i < 6; i++) std::cout<<" | "<< axe[i] ;
-  std::cout<<std::endl;
-  for (int i = 0; i < 10; i++) std::cout<< ("_____");
-  std::cout<<std::endl;  std::cout<<" b.";
-  for (int i = 0; i < 10; i++) std::cout<<" | "<<i;
-  std::cout<<std::endl;  std::cout<<"   ";
-  for (int i = 0; i < 10; i++) std::cout<<" | "<<button[i];
-  std::cout<<std::endl;
-  for (int i = 0; i < 10; i++) std::cout<< ("_____");
-  std::cout<<std::endl;
+  for (int i = 0; i < 6; i++) std::cout << "_________";
+  std::cout << std::endl; std::cout << "  axis ";
+  for (int i = 0; i < 6; i++) std::cout << " | "<<i;
+  std::cout << std::endl;  std::cout << "       ";
+  for (int i = 0; i < 6; i++) std::cout << " | "<< axe[i] ;
+  std::cout << std::endl;
+  for (int i = 0; i < 10; i++) std::cout << "_____";
+  std::cout << std::endl;  std::cout << " b.";
+  for (int i = 0; i < 10; i++) std::cout << " | " << i;
+  std::cout << std::endl;  std::cout << "   ";
+  for (int i = 0; i < 10; i++) std::cout << " | " << button[i];
+  std::cout << std::endl;
+  for (int i = 0; i < 10; i++) std::cout << "_____";
+  std::cout << std::endl;
 }
diff --git a/Common/GamePad.h b/Common/GamePad.h
index 2d7b5ccb351fc548c662afbe453331b60bf58a82..98aac25f71bd43c3cdac85d154ea003d767e5b26 100644
--- a/Common/GamePad.h
+++ b/Common/GamePad.h
@@ -13,12 +13,12 @@
 #define GP_BUTTONS 32
 #define GP_AXES 6
 
+#include "GmshConfig.h"
+
 #if defined(WIN32)
 #include <windows.h>
 #include <mmsystem.h>
-#elif defined(__APPLE__)
-// ??
-#else // LINUX
+#elif defined(HAVE_LINUX_JOYSTICK)
 #include <linux/joystick.h>
 #include <fcntl.h>
 #define GAMEPAD_DEV "/dev/input/js0"
@@ -44,28 +44,20 @@ class GamePad {
   int axe_max[8];
   int gamepad_fd;
   char name[256];
-
 #if defined(WIN32)
-
   JOYCAPS caps;
   JOYINFOEX infoex;
   JOYINFO info;
   int axes;
   int buttons;
-
-#elif defined(__APPLE__)
-
-  // ??
-  int axes;
-  int buttons;
-
-#else // LINUX
-
+#elif defined(HAVE_LINUX_JOYSTICK)
   js_event event;
   __u32 version;
   __u8 axes;
   __u8 buttons;
-
+#else
+  int axes;
+  int buttons;
 #endif
 };
 
diff --git a/Common/GmshConfig.h.in b/Common/GmshConfig.h.in
index 2fb100b29c36ed37ea9dd9ecb67ddb60ed11e277..cdba70304e4d57acad6c3075b98c84348d32ff16 100644
--- a/Common/GmshConfig.h.in
+++ b/Common/GmshConfig.h.in
@@ -27,6 +27,7 @@
 #cmakedefine HAVE_LIBJPEG
 #cmakedefine HAVE_LIBPNG
 #cmakedefine HAVE_LIBZ
+#cmakedefine HAVE_LINUX_JOYSTICK
 #cmakedefine HAVE_MATHEX
 #cmakedefine HAVE_MED
 #cmakedefine HAVE_MESH
diff --git a/Fltk/Navigator.cpp b/Fltk/Navigator.cpp
index f101570182c97d4351fa7045308c23b1defaed7d..f499a1441a0bbbe392eeb42378a02b6b4b45261c 100644
--- a/Fltk/Navigator.cpp
+++ b/Fltk/Navigator.cpp
@@ -638,7 +638,8 @@ void Navigator::move()
   }
   // head movement is damped to avoid nausea
   if(pad->button[ pad->button_map[4] ] ){
-    ax0 = int(pad->axe[ pad->axe_map[0] ]*10)/10.; ax1 =int( pad->axe[ pad->axe_map[1] ]*10)/10.;
+    ax0 = int(pad->axe[ pad->axe_map[0] ]*10)/10.;
+    ax1 =int( pad->axe[ pad->axe_map[1] ]*10)/10.;
     if(ax1 >0.) ax0=-ax0;
   }
   else     {
@@ -687,7 +688,8 @@ void Navigator::move()
     else{
       speed= -4.0 * (pad->axe[ pad->axe_map[3] ]) *reference_speed ;
     }
-    ctx->camera.move_and_look(speed,lateral,lift,0.,0.,angular_lat,azimut,elevation);
+    ctx->camera.move_and_look(speed, lateral, lift, 0., 0.,
+                              angular_lat, azimut, elevation);
     //-------------------------------------
 
     break; // end of mode PESDESTRIAN
@@ -722,7 +724,8 @@ void Navigator::move()
     angular_lat= -1.0 * (pad->axe[ pad->axe_map[2] ]) *reference_angle;
     angular_up =  1.0 * (pad->axe[ pad->axe_map[3] ]) *reference_angle;
 
-    ctx->camera.move_and_look(speed,lateral,lift,angular_fr,angular_up,angular_lat,azimut,elevation);
+    ctx->camera.move_and_look(speed, lateral, lift, angular_fr, angular_up,
+                              angular_lat, azimut, elevation);
     //-------------------------------------
     break; // end of mode DIVER