mirror of
https://github.com/WayfireWM/wf-osk.git
synced 2025-04-05 04:46:45 +02:00
cli: added command line options
This commit is contained in:
parent
ce811a718b
commit
5d26011ccc
49
src/main.cpp
49
src/main.cpp
@ -3,6 +3,8 @@
|
||||
#include <iostream>
|
||||
#include <linux/input-event-codes.h>
|
||||
|
||||
#include "util/clara.hpp"
|
||||
|
||||
#define ABC_TOGGLE 0x12345678
|
||||
#define NUM_TOGGLE 0x87654321
|
||||
|
||||
@ -19,6 +21,7 @@ namespace wf
|
||||
int default_y = 100;
|
||||
int default_width = 800;
|
||||
int default_height = 400;
|
||||
std::string anchor;
|
||||
|
||||
KeyButton::KeyButton(Key key, int width, int height)
|
||||
{
|
||||
@ -122,7 +125,7 @@ namespace wf
|
||||
Keyboard::Keyboard()
|
||||
{
|
||||
window = std::make_unique<WaylandWindow>
|
||||
(default_x, default_y, default_width, default_height);
|
||||
(default_x, default_y, default_width, default_height, anchor);
|
||||
vk = std::make_unique<VirtualKeyboardDevice> ();
|
||||
|
||||
init_layouts();
|
||||
@ -175,34 +178,26 @@ namespace wf
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct option opts[] = {
|
||||
{ "geometry", required_argument, NULL, 'g' },
|
||||
{ 0, 0, NULL, 0 }
|
||||
};
|
||||
bool show_help = false;
|
||||
|
||||
int c, i;
|
||||
while((c = getopt_long(argc, argv, "g:", opts, &i)) != -1)
|
||||
{
|
||||
using namespace wf::osk;
|
||||
switch(c)
|
||||
{
|
||||
case 'g':
|
||||
if (sscanf(optarg, "%d,%d %dx%d", &default_x, &default_y,
|
||||
&default_width, &default_height) != 4)
|
||||
{
|
||||
std::cerr << "Invalid geometry: " << optarg << std::endl;
|
||||
std::exit(-1);
|
||||
} else
|
||||
{
|
||||
std::cout << "Geometry " << default_x << "," << default_y << " "
|
||||
<< default_width << "x" << default_height;
|
||||
}
|
||||
auto cli = clara::detail::Help(show_help) |
|
||||
clara::detail::Opt(wf::osk::default_x, "int")["-x"]("x position (wf-shell only)") |
|
||||
clara::detail::Opt(wf::osk::default_y, "int")["-y"]("y position (wf-shell only)") |
|
||||
clara::detail::Opt(wf::osk::default_width, "int")["-w"]["--width"]("keyboard width") |
|
||||
clara::detail::Opt(wf::osk::default_height, "int")["-h"]["--height"]("keyboard height") |
|
||||
clara::detail::Opt(wf::osk::anchor, "top|left|bottom|right")["-a"]["--anchor"]
|
||||
("where the keyboard should anchor in the screen");
|
||||
|
||||
break;
|
||||
default:
|
||||
std::cerr << "Unrecognized argument " << char(c) << std::endl;
|
||||
}
|
||||
}
|
||||
auto res = cli.parse(clara::detail::Args(argc, argv));
|
||||
if (!res) {
|
||||
std::cerr << "Error: " << res.errorMessage() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (show_help) {
|
||||
std::cout << cli << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto app = Gtk::Application::create();
|
||||
wf::osk::Keyboard::create();
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "wayland-window.hpp"
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <gdk/gdkwayland.h>
|
||||
#include <wayland-client.h>
|
||||
|
||||
@ -98,7 +99,62 @@ namespace wf
|
||||
return instance;
|
||||
}
|
||||
|
||||
void WaylandWindow::initWayfireShell(WaylandDisplay display, int x, int y, int width, int height)
|
||||
uint32_t WaylandWindow::checkAnchorForWayfireShell(int width, int height, std::string anchor)
|
||||
{
|
||||
if (anchor.empty())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::transform(anchor.begin(), anchor.end(), anchor.begin(), ::tolower);
|
||||
|
||||
uint32_t parsed_anchor = 0;
|
||||
if (anchor.compare("top") == 0)
|
||||
{
|
||||
parsed_anchor = ZWF_WM_SURFACE_V1_ANCHOR_EDGE_TOP;
|
||||
} else if (anchor.compare("bottom") == 0)
|
||||
{
|
||||
parsed_anchor = ZWF_WM_SURFACE_V1_ANCHOR_EDGE_BOTTOM;
|
||||
} else if (anchor.compare("left") == 0)
|
||||
{
|
||||
parsed_anchor = ZWF_WM_SURFACE_V1_ANCHOR_EDGE_LEFT;
|
||||
} else if (anchor.compare("right") == 0)
|
||||
{
|
||||
parsed_anchor = ZWF_WM_SURFACE_V1_ANCHOR_EDGE_RIGHT;
|
||||
}
|
||||
|
||||
return parsed_anchor;
|
||||
}
|
||||
|
||||
uint32_t WaylandWindow::checkAnchorForLayerShell(int width, int height, std::string anchor)
|
||||
{
|
||||
if (anchor.empty())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::transform(anchor.begin(), anchor.end(), anchor.begin(), ::tolower);
|
||||
|
||||
uint32_t parsed_anchor = 0;
|
||||
if (anchor.compare("top") == 0)
|
||||
{
|
||||
parsed_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
|
||||
} else if (anchor.compare("bottom") == 0)
|
||||
{
|
||||
parsed_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
|
||||
} else if (anchor.compare("left") == 0)
|
||||
{
|
||||
parsed_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT;
|
||||
} else if (anchor.compare("right") == 0)
|
||||
{
|
||||
parsed_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
|
||||
}
|
||||
|
||||
return parsed_anchor;
|
||||
}
|
||||
|
||||
void WaylandWindow::initWayfireShell(WaylandDisplay display, int x, int y, int width,
|
||||
int height, std::string anchor)
|
||||
{
|
||||
this->show_all();
|
||||
auto gdk_window = this->get_window()->gobj();
|
||||
@ -113,11 +169,14 @@ namespace wf
|
||||
wf_surface = zwf_shell_manager_v1_get_wm_surface(display.wf_manager, surface,
|
||||
ZWF_WM_SURFACE_V1_ROLE_DESKTOP_WIDGET, nullptr);
|
||||
zwf_wm_surface_v1_set_keyboard_mode(wf_surface, ZWF_WM_SURFACE_V1_KEYBOARD_FOCUS_MODE_NO_FOCUS);
|
||||
|
||||
uint32_t parsed_anchor = checkAnchorForWayfireShell(width, height, anchor);
|
||||
zwf_wm_surface_v1_set_anchor(wf_surface, parsed_anchor);
|
||||
zwf_wm_surface_v1_configure(wf_surface, x, y);
|
||||
|
||||
}
|
||||
|
||||
void WaylandWindow::initLayerShell(WaylandDisplay display, int width, int height)
|
||||
void WaylandWindow::initLayerShell(WaylandDisplay display, int width, int height, std::string anchor)
|
||||
{
|
||||
auto gtk_window = this->gobj();
|
||||
auto gtk_widget = GTK_WIDGET(gtk_window);
|
||||
@ -145,7 +204,9 @@ namespace wf
|
||||
zwlr_layer_surface_v1_add_listener(layer_surface, &layer_surface_listener, nullptr);
|
||||
zwlr_layer_surface_v1_set_keyboard_interactivity(layer_surface, 0);
|
||||
zwlr_layer_surface_v1_set_size(layer_surface, width, height);
|
||||
zwlr_layer_surface_v1_set_anchor(layer_surface, 0);
|
||||
|
||||
uint32_t parsed_anchor = checkAnchorForLayerShell(width, height, anchor);
|
||||
zwlr_layer_surface_v1_set_anchor(layer_surface, parsed_anchor);
|
||||
|
||||
wl_surface_commit(surface);
|
||||
auto gdk_display = gdk_display_get_default();
|
||||
@ -155,7 +216,7 @@ namespace wf
|
||||
this->show_all();
|
||||
}
|
||||
|
||||
WaylandWindow::WaylandWindow(int x, int y, int width, int height)
|
||||
WaylandWindow::WaylandWindow(int x, int y, int width, int height, std::string anchor)
|
||||
: Gtk::Window()
|
||||
{
|
||||
auto display = WaylandDisplay::get();
|
||||
@ -167,10 +228,10 @@ namespace wf
|
||||
|
||||
if (display.wf_manager)
|
||||
{
|
||||
initWayfireShell(display, x, y, width, height);
|
||||
initWayfireShell(display, x, y, width, height, anchor);
|
||||
} else if (display.layer_shell)
|
||||
{
|
||||
initLayerShell(display, width, height);
|
||||
initLayerShell(display, width, height, anchor);
|
||||
} else {
|
||||
std::cerr << "Error: cannot find any supported shell protocol" << std::endl;
|
||||
std::exit(-1);
|
||||
|
@ -25,10 +25,13 @@ namespace wf
|
||||
zwf_wm_surface_v1 *wf_surface;
|
||||
zwlr_layer_surface_v1 *layer_surface;
|
||||
|
||||
void initWayfireShell(WaylandDisplay display, int x, int y, int width, int height);
|
||||
void initLayerShell(WaylandDisplay display, int width, int height);
|
||||
uint32_t checkAnchorForWayfireShell(int width, int height, std::string anchor);
|
||||
uint32_t checkAnchorForLayerShell(int width, int height, std::string anchor);
|
||||
|
||||
void initWayfireShell(WaylandDisplay display, int x, int y, int width, int height, std::string anchor);
|
||||
void initLayerShell(WaylandDisplay display, int width, int height, std::string anchor);
|
||||
|
||||
public:
|
||||
WaylandWindow(int x, int y, int width, int height);
|
||||
WaylandWindow(int x, int y, int width, int height, std::string anchor);
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user