Rev 1652 | Rev 1740 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1652 | Rev 1660 | ||
|---|---|---|---|
| Line 17... | Line 17... | ||
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
18 | * |
| 19 | */ |
19 | */ |
| 20 | 20 | ||
| 21 | #include "Xorg.h" |
21 | #include "Xorg.h" |
| 22 | - | ||
| 23 | #ifdef USE_PLUGIN_XORG |
- | |
| 24 | 22 | ||
| 25 | #include <boost/lexical_cast.hpp> |
23 | #include <boost/lexical_cast.hpp> |
| 26 | 24 | ||
| 27 | #include <X11/Xlib.h> |
25 | #include <X11/Xlib.h> |
| 28 | 26 | ||
| 29 | #include "vm/Manager.h" |
27 | #include "vm/Manager.h" |
| 30 | 28 | ||
| 31 | namespace atom { |
29 | namespace atom { |
| 32 | namespace vm { |
30 | namespace vm { |
| 33 | namespace plugin { |
31 | namespace plugin { |
| 34 | 32 | ||
| 35 | logging::Logger Xorg::LOG("vm::plugin::xorg"); |
33 | logging::Logger Xorg::LOG("vm::plugin::xorg"); |
| 36 | 34 | ||
| 37 | Xorg::Xorg(boost::asio::io_service& io_service) : Plugin(io_service) |
35 | Xorg::Xorg(boost::asio::io_service& io_service) : Plugin(io_service) |
| 38 | { |
36 | { |
| 39 | this->name_ = "xorg"; |
37 | this->name_ = "xorg"; |
| 40 | 38 | ||
| 41 | this->ExportFunction("XorgExport_SendKey", Xorg::Export_SendKey); |
39 | this->ExportFunction("XorgExport_SendKey", Xorg::Export_SendKey); |
| Line 54... | Line 52... | ||
| 54 | { |
52 | { |
| 55 | LOG.Info(output); |
53 | LOG.Info(output); |
| 56 | } |
54 | } |
| 57 | 55 | ||
| 58 | Value Xorg::Export_SendKey(const v8::Arguments& args) |
56 | Value Xorg::Export_SendKey(const v8::Arguments& args) |
| 59 | { |
57 | { |
| 60 | v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext()); |
58 | v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext()); |
| 61 | 59 | ||
| 62 | LOG.Debug(std::string(__FUNCTION__) + " called!"); |
60 | LOG.Debug(std::string(__FUNCTION__) + " called!"); |
| 63 | 61 | ||
| 64 | if (args.Length() < 1) |
62 | if (args.Length() < 1) |
| 65 | { |
63 | { |
| 66 | LOG.Error(std::string(__FUNCTION__) + ": To few arguments."); |
64 | LOG.Error(std::string(__FUNCTION__) + ": To few arguments."); |
| 67 | return v8::Boolean::New(false); |
65 | return v8::Boolean::New(false); |
| 68 | } |
66 | } |
| 69 | 67 | ||
| 70 | Display* display = XOpenDisplay(":0"); |
68 | Display* display = XOpenDisplay(":0"); |
| 71 | 69 | ||
| 72 | if (display == NULL) |
70 | if (display == NULL) |
| 73 | { |
71 | { |
| 74 | LOG.Warning("Could not locate display :0"); |
72 | LOG.Warning("Could not locate display :0"); |
| 75 | return v8::Boolean::New(false); |
73 | return v8::Boolean::New(false); |
| 76 | } |
74 | } |
| Line 98... | Line 96... | ||
| 98 | event.keycode = XKeysymToKeycode(display, args[0]->Int32Value()); |
96 | event.keycode = XKeysymToKeycode(display, args[0]->Int32Value()); |
| 99 | event.state = 0; |
97 | event.state = 0; |
| 100 | event.type = KeyPress; |
98 | event.type = KeyPress; |
| 101 | 99 | ||
| 102 | LOG.Debug("Sent code " + boost::lexical_cast<std::string>(args[0]->Int32Value())); |
100 | LOG.Debug("Sent code " + boost::lexical_cast<std::string>(args[0]->Int32Value())); |
| 103 | 101 | ||
| 104 | XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event); |
102 | XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event); |
| 105 | 103 | ||
| 106 | event.type = KeyRelease; |
104 | event.type = KeyRelease; |
| 107 | 105 | ||
| 108 | XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event); |
106 | XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event); |
| 109 | 107 | ||
| 110 | XCloseDisplay(display); |
108 | XCloseDisplay(display); |
| 111 | 109 | ||
| 112 | return v8::Boolean::New(true); |
110 | return v8::Boolean::New(true); |
| 113 | } |
111 | } |
| 114 | 112 | ||
| 115 | }; // namespace plugin |
113 | }; // namespace plugin |
| 116 | }; // namespace vm |
114 | }; // namespace vm |
| 117 | }; // namespace atom |
115 | }; // namespace atom |
| 118 | - | ||
| 119 | #endif // USE_PLUGIN_XORG |
- | |