admin管理员组文章数量:1356329
I am trying to move GtkWindow via GtkGestureLongPress. I want to implement it in VTE base terminal app. My script is given below. The problem is -
I ran the ping(ping 127.0.0.1) command in the terminal, when I tried to move the window by long pressing, the vte terminal stopped updating (output of the ping command pause). Unable to release it from the longpress event, need to click on the window/terminal to see the terminal output (updated output of ping command).
Can anybody check it please?
#include <gtk/gtk.h>
#include <vte/vte.h>
GtkWidget *window;
GtkWidget *terminal;
static void
child_ready(VteTerminal *terminal, GPid pid, GError *error, gpointer user_data)
{
if (!terminal) return;
if (pid == -1) gtk_window_destroy((GtkWindow *)window);
}
static void run_terminal()
{
/* Start a new shell */
gchar **envp = g_get_environ();
//gchar **command = (gchar *[]){g_strdup(g_environ_getenv(envp, "SHELL")), NULL};
gchar **command = (gchar *[]){g_strdup(g_environ_getenv(envp, "SHELL")),
"-c", "/bin/bash", NULL};
g_strfreev(envp);
/* Spawn terminal asynchronously */
vte_terminal_spawn_async(VTE_TERMINAL(terminal),
VTE_PTY_DEFAULT, /* pty flag */
NULL, /* working directory */
command, /* argv */
NULL, /* environment variables */
G_SPAWN_DEFAULT, /* spawn flag */
NULL, /* child setup function */
NULL, /* child setup data */
NULL, /* child setup data destroy */
-1, /* timeout */
NULL, /* cancellable */
child_ready, /* async callback */
NULL); /* callback data */
}
void drag_on_long_press (GtkGestureLongPress* gesture,
gdouble x,
gdouble y,
gpointer user_data)
{
GdkSurface *surface;
GdkEvent *event;
guint btn;
const graphene_point_t *point = graphene_point_init (graphene_point_alloc (), x, y);
graphene_point_t *point1 = graphene_point_init (graphene_point_alloc (), x, y);
GdkEventSequence *sequence = gtk_gesture_get_last_updated_sequence ((GtkGesture *)gesture);
event = gtk_gesture_get_last_event ((GtkGesture *)gesture, sequence);
GtkWidget *widget = gtk_event_controller_get_widget ((GtkEventController *)gesture);
GdkDevice *device = gtk_gesture_get_device ((GtkGesture *)gesture);
guint32 timestamp = gdk_event_get_time (event);
if (gdk_event_get_event_type (event) == GDK_BUTTON_PRESS){
btn = gdk_button_event_get_button (event);
if (!gtk_widget_compute_point (widget, GTK_WIDGET (gtk_widget_get_root (widget)), point, point1))
return;
surface = gtk_native_get_surface (gtk_widget_get_native (widget));
gdk_toplevel_begin_move(GDK_TOPLEVEL (surface), device,
btn, x+12, y+12, timestamp);
gtk_event_controller_reset ((GtkEventController *)gesture);
}else{
btn = 0;
}
graphene_point_free(point1);
free((void*)point);
}
static void
activate (GtkApplication *app,
gpointer user_data)
{
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Window");
gtk_window_set_default_size (GTK_WINDOW (window), 660, 300);
GtkGesture* ges = gtk_gesture_long_press_new();
gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(ges), GDK_BUTTON_PRIMARY);
gtk_event_controller_set_propagation_phase((GtkEventController *)ges, GTK_PHASE_CAPTURE);
gtk_widget_add_controller (window, GTK_EVENT_CONTROLLER (ges));
g_signal_connect (ges, "pressed", G_CALLBACK (drag_on_long_press), NULL);
GtkWidget *scrollview;
scrollview = gtk_scrolled_window_new();
gtk_window_set_child ((GtkWindow *)window, scrollview);
terminal = vte_terminal_new();
gtk_scrolled_window_set_child ((GtkScrolledWindow *)scrollview, terminal);
run_terminal();
gtk_window_present ((GtkWindow *)window);
}
int
main (int argc,
char **argv)
{
GtkApplication *app;
int status;
app = gtk_application_new (".gtk.example", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
本文标签: cHow to drag amp drop (move) GtkWindow using GtkGestureLongPressStack Overflow
版权声明:本文标题:c - How to drag & drop (move) GtkWindow using GtkGestureLongPress? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743967310a2570123.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论