今天终于解决了这个难题, 围绕它已经折磨我好久了 . 现在把心得写下, 以便同仁和自己以后参考.
根据GTK+的外观设置API :
gtk_window_set_decorated (window,FALSE); 这个API可以创建无标题栏的窗体. 二话不说, 直接查找API的源代码:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1
void
gtk_window_set_decorated (GtkWindow
*
window,gboolean setting)
2 {
3 ... gdk_window_set_decorations (GTK_WIDGET (window) -> window,GDK_DECOR_ALL);
4 else
5 gdk_window_set_decorations (GTK_WIDGET (window) -> window, 0 );
6 ...}
7
2 {
3 ... gdk_window_set_decorations (GTK_WIDGET (window) -> window,GDK_DECOR_ALL);
4 else
5 gdk_window_set_decorations (GTK_WIDGET (window) -> window, 0 );
6 ...}
7
再往下找(在gdk的X11里面找):
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1
void
gdk_window_set_decorations (GdkWindow
*
window,GdkWMDecoration decorations)
2 {
3 MotifWmHints hints;
4
5 g_return_if_fail (GDK_IS_WINDOW (window));
6 hints.flags = MWM_HINTS_DECORATIONS;
7 hints.decorations = decorations;
8 gdk_window_set_mwm_hints (window, & hints);
9 }
10
11
2 {
3 MotifWmHints hints;
4
5 g_return_if_fail (GDK_IS_WINDOW (window));
6 hints.flags = MWM_HINTS_DECORATIONS;
7 hints.decorations = decorations;
8 gdk_window_set_mwm_hints (window, & hints);
9 }
10
11
again:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1
static
void
gdk_window_set_mwm_hints (GdkWindow
*
window,MotifWmHints
*
new_hints)
2 {
3 GdkDisplay * display;
4 Atom hints_atom = None;
5 guchar * data;
6 MotifWmHints * hints;
7 Atom type;
8 gint format;
9 gulong nitems;
10 gulong bytes_after;
11
12 if (GDK_WINDOW_DESTROYED (window))
13 return ;
14
15 display = gdk_drawable_get_display (window);
16 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
17
18 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
19 hints_atom, 0 , sizeof (MotifWmHints) / sizeof ( long ),
20 False, AnyPropertyType, & type, & format, & nitems,
21 & bytes_after, & data);
22
23 if (type == None)
24 hints = new_hints;
25 else
26 {
27 hints = (MotifWmHints * )data;
28
29 if (new_hints -> flags & MWM_HINTS_FUNCTIONS)
30 {
31 hints -> flags |= MWM_HINTS_FUNCTIONS;
32 hints -> functions = new_hints -> functions;
33 }
34 if (new_hints -> flags & MWM_HINTS_DECORATIONS)
35 {
36 hints -> flags |= MWM_HINTS_DECORATIONS;
37 hints -> decorations = new_hints -> decorations;
38 }
39 }
40
41 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
42 hints_atom, hints_atom, 32 , PropModeReplace,
43 (guchar * )hints, sizeof (MotifWmHints) / sizeof ( long ));
44
45 if (hints != new_hints)
46 XFree (hints);
47 }
48
49
2 {
3 GdkDisplay * display;
4 Atom hints_atom = None;
5 guchar * data;
6 MotifWmHints * hints;
7 Atom type;
8 gint format;
9 gulong nitems;
10 gulong bytes_after;
11
12 if (GDK_WINDOW_DESTROYED (window))
13 return ;
14
15 display = gdk_drawable_get_display (window);
16 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
17
18 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
19 hints_atom, 0 , sizeof (MotifWmHints) / sizeof ( long ),
20 False, AnyPropertyType, & type, & format, & nitems,
21 & bytes_after, & data);
22
23 if (type == None)
24 hints = new_hints;
25 else
26 {
27 hints = (MotifWmHints * )data;
28
29 if (new_hints -> flags & MWM_HINTS_FUNCTIONS)
30 {
31 hints -> flags |= MWM_HINTS_FUNCTIONS;
32 hints -> functions = new_hints -> functions;
33 }
34 if (new_hints -> flags & MWM_HINTS_DECORATIONS)
35 {
36 hints -> flags |= MWM_HINTS_DECORATIONS;
37 hints -> decorations = new_hints -> decorations;
38 }
39 }
40
41 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
42 hints_atom, hints_atom, 32 , PropModeReplace,
43 (guchar * )hints, sizeof (MotifWmHints) / sizeof ( long ));
44
45 if (hints != new_hints)
46 XFree (hints);
47 }
48
49
就是它了 创建无装饰窗体的核心代码就是它了. 再从中进行分析, 我封装出了这样的函数代码:
x
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1
static
void
gdk_window_set_mwm_hints (GdkWindow
*
window,MotifWmHints
*
new_hints)
2 {
3 GdkDisplay * display;
4 Atom hints_atom = None;
5 guchar * data;
6 MotifWmHints * hints;
7 Atom type;
8 gint format;
9 gulong nitems;
10 gulong bytes_after;
11
12 if (GDK_WINDOW_DESTROYED (window))
13 return ;
14
15 display = gdk_drawable_get_display (window);
16 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
17
18 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
19 hints_atom, 0 , sizeof (MotifWmHints) / sizeof ( long ),
20 False, AnyPropertyType, & type, & format, & nitems,
21 & bytes_after, & data);
22
23 if (type == None)
24 hints = new_hints;
25 else
26 {
27 hints = (MotifWmHints * )data;
28
29 if (new_hints -> flags & MWM_HINTS_FUNCTIONS)
30 {
31 hints -> flags |= MWM_HINTS_FUNCTIONS;
32 hints -> functions = new_hints -> functions;
33 }
34 if (new_hints -> flags & MWM_HINTS_DECORATIONS)
35 {
36 hints -> flags |= MWM_HINTS_DECORATIONS;
37 hints -> decorations = new_hints -> decorations;
38 }
39 }
40
41 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
42 hints_atom, hints_atom, 32 , PropModeReplace,
43 (guchar * )hints, sizeof (MotifWmHints) / sizeof ( long ));
44
45 if (hints != new_hints)
46 XFree (hints);
47 }
48
49
2 {
3 GdkDisplay * display;
4 Atom hints_atom = None;
5 guchar * data;
6 MotifWmHints * hints;
7 Atom type;
8 gint format;
9 gulong nitems;
10 gulong bytes_after;
11
12 if (GDK_WINDOW_DESTROYED (window))
13 return ;
14
15 display = gdk_drawable_get_display (window);
16 hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
17
18 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
19 hints_atom, 0 , sizeof (MotifWmHints) / sizeof ( long ),
20 False, AnyPropertyType, & type, & format, & nitems,
21 & bytes_after, & data);
22
23 if (type == None)
24 hints = new_hints;
25 else
26 {
27 hints = (MotifWmHints * )data;
28
29 if (new_hints -> flags & MWM_HINTS_FUNCTIONS)
30 {
31 hints -> flags |= MWM_HINTS_FUNCTIONS;
32 hints -> functions = new_hints -> functions;
33 }
34 if (new_hints -> flags & MWM_HINTS_DECORATIONS)
35 {
36 hints -> flags |= MWM_HINTS_DECORATIONS;
37 hints -> decorations = new_hints -> decorations;
38 }
39 }
40
41 XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
42 hints_atom, hints_atom, 32 , PropModeReplace,
43 (guchar * )hints, sizeof (MotifWmHints) / sizeof ( long ));
44
45 if (hints != new_hints)
46 XFree (hints);
47 }
48
49
make 运行 .
PS: 典型的窗口管理程序的应用问题 不过要找到这个点还真费了不少事 .希望对大家有所帮助。