检测GTK窗口何时由用户移动/调整大小 [英] Detecting when a GTK window is done moving/resizing by the user

查看:154
本文介绍了检测GTK窗口何时由用户移动/调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检测用户何时完成调整大小或移动GTK窗口.基本上等效于 WM_EXITSIZEMOVE 在Windows中.

I want to detect when the user finished re-sizing or moving the GTK window. Basically an equivalent of WM_EXITSIZEMOVE in windows.

我查看了 GTK检测用户调整窗口大小的方法并能够使用configure-event检测大小/位置更改;但是,由于我的其他代码是架构师,因此我想知道调整大小的时间.类似于ValueChanged而不是ValueChanging事件.

I have looked at GTK detecting window resize from the user and am able to detect size/location changes using the configure-event; however because of how my other code is architect I want to know when the resizing is done. Almost like ValueChanged instead of ValueChanging event.

我在想是否可以找到是否释放了鼠标按钮,然后尝试检测它是否是我遇到的最后一个事件.但是,对于一个窗口对象,也找不到任何一种方法.

I was thinking if i could find out is the mouse button is released or not and then try to detect if it was the last event I got. But can't find a way to do that either for a window object.

推荐答案

您可以使用一个超时函数,该函数在调整大小后将被调用.超时以毫秒为单位,您可能需要使用该值来在调用resize_done和在真正完成调整大小之前触发它的延迟之间取得平衡.

You could use a timeout function that gets called once the resizing is done. The timeout is in ms, you might want to play with the value to get a balance between the delay in calling resize_done and triggering it before the resize is really done.

#define TIMEOUT 250

gboolean resize_done (gpointer data)
{
  guint *id = data;
  *id = 0;
  /* call your existing code here */
  return FALSE;
}

gboolean on_configure_event (GtkWidget *window, GdkEvent *event, gpointer data)
{
  static guint id = 0;
  if (id)
    g_source_remove (id);
  id = g_timeout_add (TIMEOUT, resize_done, &id);
  return FALSE;
}

这篇关于检测GTK窗口何时由用户移动/调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆