terminal: Add context menu with new terminal/copy/paste
This commit is contained in:
parent
14f39b290b
commit
67b8215bcb
@ -142,7 +142,7 @@ sigchild_handler(int s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
menu_func(struct window *window, int index, void *data)
|
menu_func(struct window *window, struct input *input, int index, void *data)
|
||||||
{
|
{
|
||||||
printf("Selected index %d from a panel menu.\n", index);
|
printf("Selected index %d from a panel menu.\n", index);
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,8 @@ key_handler(struct window *window, struct input *input, uint32_t time,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
menu_func(struct window *window, int index, void *user_data)
|
menu_func(struct window *window,
|
||||||
|
struct input *input, int index, void *user_data)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "picked entry %d\n", index);
|
fprintf(stderr, "picked entry %d\n", index);
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,8 @@
|
|||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
|
||||||
|
#include <linux/input.h>
|
||||||
|
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
|
|
||||||
#include "../shared/config-parser.h"
|
#include "../shared/config-parser.h"
|
||||||
@ -2211,38 +2213,54 @@ close_handler(struct window *window, void *data)
|
|||||||
terminal_destroy(terminal);
|
terminal_destroy(terminal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
terminal_copy(struct terminal *terminal, struct input *input)
|
||||||
|
{
|
||||||
|
terminal->selection =
|
||||||
|
display_create_data_source(terminal->display);
|
||||||
|
wl_data_source_offer(terminal->selection,
|
||||||
|
"text/plain;charset=utf-8");
|
||||||
|
wl_data_source_add_listener(terminal->selection,
|
||||||
|
&data_source_listener, terminal);
|
||||||
|
input_set_selection(input, terminal->selection,
|
||||||
|
display_get_serial(terminal->display));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
terminal_paste(struct terminal *terminal, struct input *input)
|
||||||
|
{
|
||||||
|
input_receive_selection_data_to_fd(input,
|
||||||
|
"text/plain;charset=utf-8",
|
||||||
|
terminal->master);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
terminal_new_instance(struct terminal *terminal)
|
||||||
|
{
|
||||||
|
struct terminal *new_terminal;
|
||||||
|
|
||||||
|
new_terminal = terminal_create(terminal->display);
|
||||||
|
if (terminal_run(new_terminal, option_shell))
|
||||||
|
terminal_destroy(new_terminal);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
handle_bound_key(struct terminal *terminal,
|
handle_bound_key(struct terminal *terminal,
|
||||||
struct input *input, uint32_t sym, uint32_t time)
|
struct input *input, uint32_t sym, uint32_t time)
|
||||||
{
|
{
|
||||||
struct terminal *new_terminal;
|
|
||||||
|
|
||||||
switch (sym) {
|
switch (sym) {
|
||||||
case XKB_KEY_X:
|
case XKB_KEY_X:
|
||||||
/* Cut selection; terminal doesn't do cut, fall
|
/* Cut selection; terminal doesn't do cut, fall
|
||||||
* through to copy. */
|
* through to copy. */
|
||||||
case XKB_KEY_C:
|
case XKB_KEY_C:
|
||||||
terminal->selection =
|
terminal_copy(terminal, input);
|
||||||
display_create_data_source(terminal->display);
|
|
||||||
wl_data_source_offer(terminal->selection,
|
|
||||||
"text/plain;charset=utf-8");
|
|
||||||
wl_data_source_add_listener(terminal->selection,
|
|
||||||
&data_source_listener, terminal);
|
|
||||||
input_set_selection(input, terminal->selection,
|
|
||||||
display_get_serial(terminal->display));
|
|
||||||
return 1;
|
return 1;
|
||||||
case XKB_KEY_V:
|
case XKB_KEY_V:
|
||||||
input_receive_selection_data_to_fd(input,
|
terminal_paste(terminal, input);
|
||||||
"text/plain;charset=utf-8",
|
|
||||||
terminal->master);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case XKB_KEY_N:
|
case XKB_KEY_N:
|
||||||
new_terminal = terminal_create(terminal->display);
|
terminal_new_instance(terminal);
|
||||||
if (terminal_run(new_terminal, option_shell))
|
|
||||||
terminal_destroy(new_terminal);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case XKB_KEY_Up:
|
case XKB_KEY_Up:
|
||||||
@ -2629,6 +2647,40 @@ recompute_selection(struct terminal *terminal)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
menu_func(struct window *window, struct input *input, int index, void *data)
|
||||||
|
{
|
||||||
|
struct terminal *terminal = data;
|
||||||
|
|
||||||
|
fprintf(stderr, "picked entry %d\n", index);
|
||||||
|
|
||||||
|
switch (index) {
|
||||||
|
case 0:
|
||||||
|
terminal_new_instance(terminal);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
terminal_copy(terminal, input);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
terminal_paste(terminal, input);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
show_menu(struct terminal *terminal, struct input *input, uint32_t time)
|
||||||
|
{
|
||||||
|
int32_t x, y;
|
||||||
|
static const char *entries[] = {
|
||||||
|
"Open Terminal", "Copy", "Paste"
|
||||||
|
};
|
||||||
|
|
||||||
|
input_get_position(input, &x, &y);
|
||||||
|
window_show_menu(terminal->display, input, time, terminal->window,
|
||||||
|
x - 10, y - 10, menu_func,
|
||||||
|
entries, ARRAY_LENGTH(entries));
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
button_handler(struct widget *widget,
|
button_handler(struct widget *widget,
|
||||||
struct input *input, uint32_t time,
|
struct input *input, uint32_t time,
|
||||||
@ -2638,7 +2690,7 @@ button_handler(struct widget *widget,
|
|||||||
struct terminal *terminal = data;
|
struct terminal *terminal = data;
|
||||||
|
|
||||||
switch (button) {
|
switch (button) {
|
||||||
case 272:
|
case BTN_LEFT:
|
||||||
if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
||||||
|
|
||||||
if (time - terminal->button_time < 500)
|
if (time - terminal->button_time < 500)
|
||||||
@ -2661,6 +2713,11 @@ button_handler(struct widget *widget,
|
|||||||
terminal->dragging = SELECT_NONE;
|
terminal->dragging = SELECT_NONE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case BTN_RIGHT:
|
||||||
|
if (state == WL_POINTER_BUTTON_STATE_PRESSED)
|
||||||
|
show_menu(terminal, input, time);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2263,7 +2263,8 @@ frame_get_pointer_image_for_location(struct window_frame *frame,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
frame_menu_func(struct window *window, int index, void *data)
|
frame_menu_func(struct window *window,
|
||||||
|
struct input *input, int index, void *data)
|
||||||
{
|
{
|
||||||
struct display *display;
|
struct display *display;
|
||||||
|
|
||||||
@ -4377,7 +4378,7 @@ menu_button_handler(struct widget *widget,
|
|||||||
(menu->release_count > 0 || time - menu->time > 500)) {
|
(menu->release_count > 0 || time - menu->time > 500)) {
|
||||||
/* Either relase after press-drag-release or
|
/* Either relase after press-drag-release or
|
||||||
* click-motion-click. */
|
* click-motion-click. */
|
||||||
menu->func(menu->window->parent,
|
menu->func(menu->window->parent, input,
|
||||||
menu->current, menu->window->parent->user_data);
|
menu->current, menu->window->parent->user_data);
|
||||||
input_ungrab(input);
|
input_ungrab(input);
|
||||||
menu_destroy(menu);
|
menu_destroy(menu);
|
||||||
|
@ -277,7 +277,8 @@ window_create_custom(struct display *display);
|
|||||||
int
|
int
|
||||||
window_has_focus(struct window *window);
|
window_has_focus(struct window *window);
|
||||||
|
|
||||||
typedef void (*menu_func_t)(struct window *window, int index, void *data);
|
typedef void (*menu_func_t)(struct window *window,
|
||||||
|
struct input *input, int index, void *data);
|
||||||
|
|
||||||
void
|
void
|
||||||
window_show_menu(struct display *display,
|
window_show_menu(struct display *display,
|
||||||
|
Loading…
Reference in New Issue
Block a user