Back to index

easystroke  0.5.5.1
Public Member Functions | Private Member Functions | Private Attributes
Main Class Reference
Collaboration diagram for Main:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Main ()
void run ()
bool handle (Glib::IOCondition)
void handle_enter_leave (XEvent &ev)
void handle_event (XEvent &ev)
void handle_xi2_event (XIDeviceEvent *event)
void handle_raw_motion (XIRawEvent *event)
void report_xi2_event (XIDeviceEvent *event, const char *type)
 ~Main ()

Private Member Functions

std::string parse_args_and_init_gtk ()
void create_config_dir ()
char * next_event ()
void usage (char *me, bool good)
void version ()

Private Attributes

std::string display
Gtk::Main * kit

Detailed Description

Definition at line 1090 of file main.cc.


Constructor & Destructor Documentation

Definition at line 1146 of file main.cc.

           : kit(0) {
       bindtextdomain("easystroke", is_dir("po") ? "po" : LOCALEDIR);
       bind_textdomain_codeset("easystroke", "UTF-8");
       textdomain("easystroke");
       if (0) {
              RStroke trefoil = Stroke::trefoil();
              trefoil->draw_svg("easystroke.svg");
              exit(EXIT_SUCCESS);
       }
       if (argc > 1 && !strcmp(argv[1], "send")) {
              if (argc == 2)
                     usage(argv[0], false);
              gtk_init(&argc, &argv);
              send_dbus(argv[2]);
              exit(EXIT_SUCCESS);
       }

       display = parse_args_and_init_gtk();
       create_config_dir();
       unsetenv("DESKTOP_AUTOSTART_ID");

       signal(SIGINT, &quit);
       signal(SIGCHLD, SIG_IGN);

       Gtk::LinkButton::set_uri_hook(sigc::ptr_fun(&link_button_hook));
       Gtk::AboutDialog::set_url_hook(sigc::ptr_fun(&about_dialog_hook));

       dpy = XOpenDisplay(display.c_str());
       if (!dpy) {
              printf(_("Couldn't open display.\n"));
              exit(EXIT_FAILURE);
       }
       if (!no_dbus && start_dbus() < 0) {
              printf(_("Easystroke is already running, showing configuration window instead.\n"));
              send_dbus("");
              exit(EXIT_SUCCESS);
       }
       ROOT = DefaultRootWindow(dpy);

       ping_window = XCreateSimpleWindow(dpy, ROOT, 0, 0, 1, 1, 0, 0, 0);

       prefs.init();
       action_watcher = new ActionDBWatcher;
       action_watcher->init();

       grabber = new Grabber;
       // Force enter events to be generated
       XGrabPointer(dpy, ROOT, False, 0, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
       XUngrabPointer(dpy, CurrentTime);

       trace.reset(init_trace());
       Glib::RefPtr<Gdk::Screen> screen = Gdk::Display::get_default()->get_default_screen();
       g_signal_connect(screen->gobj(), "composited-changed", &schedule_reload_trace, NULL);
       screen->signal_size_changed().connect(sigc::ptr_fun(&schedule_reload_trace));
       Notifier *trace_notify = new Notifier(sigc::ptr_fun(&schedule_reload_trace));
       prefs.trace.connect(trace_notify);
       prefs.color.connect(trace_notify);

       handler = new IdleHandler;
       handler->init();
       XTestGrabControl(dpy, True);

}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1539 of file main.cc.

            {
       trace->end();
       trace.reset();
       delete grabber;
       delete kit;
       XCloseDisplay(dpy);
       prefs.execute_now();
       action_watcher->execute_now();
}

Here is the call graph for this function:


Member Function Documentation

void Main::create_config_dir ( ) [private]

Definition at line 1329 of file main.cc.

                             {
       if (config_dir == "") {
              config_dir = getenv("HOME");
              config_dir += "/.easystroke";
       }
       struct stat st;
       char *name = canonicalize_file_name(config_dir.c_str());

       // check if the directory does not exist
       if (lstat(name, &st) == -1) {
              if (mkdir(config_dir.c_str(), 0777) == -1) {
                     printf(_("Error: Couldn't create configuration directory \"%s\"\n"), config_dir.c_str());
                     exit(EXIT_FAILURE);
              }
       } else {
              if (!S_ISDIR(st.st_mode)) {
                     printf(_("Error: \"%s\" is not a directory\n"), config_dir.c_str());
                     exit(EXIT_FAILURE);
              }


       }
       free (name);
       config_dir += "/";
}

Here is the caller graph for this function:

bool Main::handle ( Glib::IOCondition  )

Definition at line 1524 of file main.cc.

                                 {
       while (XPending(dpy)) {
              try {
                     XEvent ev;
                     XNextEvent(dpy, &ev);
                     if (!grabber->handle(ev))
                            handle_event(ev);
              } catch (GrabFailedException &e) {
                     printf(_("Error: %s\n"), e.what());
                     bail_out();
              }
       }
       return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Main::handle_enter_leave ( XEvent &  ev)

Definition at line 1357 of file main.cc.

                                        {
       if (ev.xcrossing.mode == NotifyGrab)
              return;
       if (ev.xcrossing.detail == NotifyInferior)
              return;
       Window w = ev.xcrossing.window;
       if (ev.type == EnterNotify) {
              current_app_window.set(get_app_window(w));
              if (verbosity >= 3)
                     printf("Entered window 0x%lx -> 0x%lx\n", w, current_app_window.get());
       } else printf("Error: Bogus Enter/Leave event\n");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Main::handle_event ( XEvent &  ev)

Definition at line 1371 of file main.cc.

                                  {

       switch(ev.type) {
       case EnterNotify:
       case LeaveNotify:
              handle_enter_leave(ev);
              return;

       case PropertyNotify:
              if (current_app_window.get() == ev.xproperty.window && ev.xproperty.atom == XA_WM_CLASS)
                     current_app_window.notify();
              return;

       case ButtonPress:
              if (verbosity >= 3)
                     printf("Press (master): %d (%d, %d) at t = %ld\n", ev.xbutton.button, ev.xbutton.x, ev.xbutton.y, ev.xbutton.time);
                     H->press_master(ev.xbutton.button, ev.xbutton.time);
              return;

       case ClientMessage:
              if (ev.xclient.window != ping_window)
                     return;
              if (ev.xclient.message_type == *EASYSTROKE_PING) {
                     if (verbosity >= 3)
                            printf("Pong\n");
                     H->pong();
              }
              return;

       case MappingNotify:
              if (ev.xmapping.request != MappingPointer)
                     return;
              update_core_mapping();
              return;
       case GenericEvent:
              if (ev.xcookie.extension == grabber->opcode && XGetEventData(dpy, &ev.xcookie)) {
                     handle_xi2_event((XIDeviceEvent *)ev.xcookie.data);
                     XFreeEventData(dpy, &ev.xcookie);
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Main::handle_raw_motion ( XIRawEvent *  event)

Definition at line 1495 of file main.cc.

                                              {
       if (!current_dev || current_dev->dev != event->deviceid)
              return;
       double x = 0.0, y = 0.0;
       bool abs_x = current_dev->absolute;
       bool abs_y = current_dev->absolute;
       int i = 0;

       if (XIMaskIsSet(event->valuators.mask, 0))
              x = event->raw_values[i++];
       else
              abs_x = false;

       if (XIMaskIsSet(event->valuators.mask, 1))
              y = event->raw_values[i++];
       else
              abs_y = false;

       if (verbosity >= 5) {
              printf("Raw motion (XI2): (");
              print_coordinates(&event->valuators, event->raw_values);
              printf(") at t = %ld\n", event->time);
       }

       H->raw_motion(create_triple(x * current_dev->scale_x, y * current_dev->scale_y, event->time), abs_x, abs_y);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Main::handle_xi2_event ( XIDeviceEvent *  event)

Definition at line 1443 of file main.cc.

                                                {
       switch (event->evtype) {
              case XI_ButtonPress:
                     if (verbosity >= 3)
                            report_xi2_event(event, "Press");
                     if (xinput_pressed.size()) {
                            if (!current_dev || current_dev->dev != event->deviceid)
                                   break;
                     }
                     current_dev = grabber->get_xi_dev(event->deviceid);
                     if (!current_dev) {
                            printf("Warning: Spurious device event\n");
                            break;
                     }
                     if (current_dev->master)
                            XISetClientPointer(dpy, None, current_dev->master);
                     xinput_pressed.insert(event->detail);
                     H->press(event->detail, create_triple(event->root_x, event->root_y, event->time));
                     break;
              case XI_ButtonRelease:
                     if (verbosity >= 3)
                            report_xi2_event(event, "Release");
                     if (!current_dev || current_dev->dev != event->deviceid)
                            break;
                     xinput_pressed.erase(event->detail);
                     H->release(event->detail, create_triple(event->root_x, event->root_y, event->time));
                     break;
              case XI_Motion:
                     if (verbosity >= 5)
                            report_xi2_event(event, "Motion");
                     if (!current_dev || current_dev->dev != event->deviceid)
                            break;
                     if (current_dev->supports_pressure && XIMaskIsSet(event->valuators.mask, 2)) {
                            int i = 0;
                            if (XIMaskIsSet(event->valuators.mask, 0))
                                   i++;
                            if (XIMaskIsSet(event->valuators.mask, 1))
                                   i++;
                            int z = current_dev->normalize_pressure(event->valuators.values[i]);
                            if (prefs.pressure_abort.get() && z >= prefs.pressure_threshold.get())
                                   H->pressure();
                     }
                     H->motion(create_triple(event->root_x, event->root_y, event->time));
                     break;
              case XI_RawMotion:
                     handle_raw_motion((XIRawEvent *)event);
                     break;
              case XI_HierarchyChanged:
                     grabber->hierarchy_changed((XIHierarchyEvent *)event);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* Main::next_event ( ) [private]
std::string Main::parse_args_and_init_gtk ( ) [private]

Definition at line 1258 of file main.cc.

                                        {
       static struct option long_opts1[] = {
              {"display",1,0,'d'},
              {"help",0,0,'h'},
              {"version",0,0,'V'},
              {"show-gui",0,0,'g'},
              {0,0,0,0}
       };
       static struct option long_opts2[] = {
              {"config-dir",1,0,'c'},
              {"display",1,0,'d'},
              {"experimental",0,0,'e'},
              {"show-gui",0,0,'g'},
              {"verbose",0,0,'v'},
              {"no-dbus",0,0,'D'},
              {"disabled",0,0,'x'},
              {0,0,0,0}
       };
       std::string display;
       int opt;
       // parse --display here, before Gtk::Main(...) takes it away from us
       opterr = 0;
       while ((opt = getopt_long(argc, argv, "gh", long_opts1, 0)) != -1)
              switch (opt) {
                     case 'd':
                            display = optarg;
                            break;
                     case 'g':
                            show_gui = true;
                            break;
                     case 'h':
                            usage(argv[0], true);
                            break;
                     case 'V':
                            version();
                            break;
              }
       optind = 1;
       opterr = 1;
       kit = new Gtk::Main(argc, argv);
       oldHandler = XSetErrorHandler(xErrorHandler);
       oldIOHandler = XSetIOErrorHandler(xIOErrorHandler);

       while ((opt = getopt_long(argc, argv, "c:egvDx", long_opts2, 0)) != -1) {
              switch (opt) {
                     case 'c':
                            config_dir = optarg;
                            break;
                     case 'e':
                            experimental = true;
                            break;
                     case 'v':
                            verbosity++;
                            break;
                     case 'D':
                            no_dbus = true;
                            break;
                     case 'x':
                            disabled.set(true);
                            break;
                     case 'd':
                     case 'n':
                     case 'g':
                            break;
                     default:
                            usage(argv[0], false);
              }
       }
       return display;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Main::report_xi2_event ( XIDeviceEvent *  event,
const char *  type 
)

Definition at line 1434 of file main.cc.

                                                                  {
       printf("%s (XI2): ", type);
       if (event->detail)
              printf("%d ", event->detail);
       printf("(%.3f, %.3f) - (", event->root_x, event->root_y);
       print_coordinates(&event->valuators, event->valuators.values);
       printf(") at t = %ld\n", event->time);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Main::run ( )

Definition at line 1212 of file main.cc.

               {
       Glib::RefPtr<Glib::IOSource> io = Glib::IOSource::create(ConnectionNumber(dpy), Glib::IO_IN);
       io->connect(sigc::mem_fun(*this, &Main::handle));
       io->attach();
       try {
              widgets = Gtk::Builder::create_from_string(gui_buffer);
       } catch (Gtk::BuilderError &e) {
              printf("Error building GUI: %s\n", e.what().c_str());
              exit(EXIT_FAILURE);
       }
       win = new Win;
       if (show_gui)
              win->get_window().show();
       Gtk::Main::run();
       delete win;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Main::usage ( char *  me,
bool  good 
) [private]

Definition at line 1229 of file main.cc.

                                    {
       printf("The full easystroke documentation is available at the following address:\n");
       printf("\n");
       printf("http://easystroke.wiki.sourceforge.net/Documentation#content\n");
       printf("\n");
       printf("Usage: %s [OPTION]...\n", me);
       printf("or:    %s send <action_name>\n", me);
       printf("\n");
       printf("Options:\n");
       printf("  -c, --config-dir       Directory for config files\n");
       printf("      --display          X Server to contact\n");
       printf("  -D  --no-dbus          Don't try to register as a DBus service\n");
       printf("  -e  --experimental     Start in experimental mode\n");
       printf("  -g, --show-gui         Show the configuration dialog on startup\n");
       printf("  -x  --disable          Start disabled\n");
       printf("  -v, --verbose          Increase verbosity level\n");
       printf("  -h, --help             Display this help and exit\n");
       printf("      --version          Output version information and exit\n");
       exit(good ? EXIT_SUCCESS : EXIT_FAILURE);
}

Here is the caller graph for this function:

void Main::version ( ) [private]

Definition at line 1251 of file main.cc.

                   {
       printf("easystroke %s\n", version_string);
       printf("\n");
       printf("Written by Thomas Jaeger <ThJaeger@gmail.com>.\n");
       exit(EXIT_SUCCESS);
}

Here is the caller graph for this function:


Member Data Documentation

std::string Main::display [private]

Definition at line 1097 of file main.cc.

Gtk::Main* Main::kit [private]

Definition at line 1098 of file main.cc.


The documentation for this class was generated from the following file: