clusterssh (Cssh) KDE下无法正确重排窗口的问题

cssh 是一个不错的多服务器登录工具, 采用平铺窗口的方式, 相比konsole的多tab, 更来得直观。 我也把它融合到自己的myssh中。

cssh在打开多窗口后, 会有个重排窗口使之不重叠的功能, 之前在gnome下用很正常, 但现在换到KDE, 却发现重排后依然没变化,乱且重叠了。搜了下,还真没找到啥解决方法, 想想cssh是perl写的, 就硬着头皮看看, 希望能解决这个小问题

稍微看了下函数, 发现有个与窗口重排有关的send_resizemove, 从函数名应该可以猜到它的作用。 整个cssh中, 只有一处地方调用了这函数. 大概在1367行。

logmsg( 2, "Moving $server window" );
        send_resizemove(
            $servers{$server}{wid},
            $current_x, $current_y,
            $config{internal_terminal_width},    #该参数指定了重排时窗口的新宽度
            $config{internal_terminal_height}    #该参数指定了重排时窗口的新高度
        );

我修改了代码中最后两个参数, 并打开logmsg的调试信息, 希望能找到无法重排及重新调整窗口大小的问题。 写死了新的窗口大小, 但出来的结果却是只有最后一个窗口会改变大小, 其他窗口都没变化, 这倒很有意思, 不是send_resizemove无法起作用, 而是无法在全部窗口起作用。

Tiling top left going bot right
x:5 y:5, r:0 c:0
Moving 15.238.122.15  window
Moving window 65011726 to x:5 y:5 (size x:488 y:242)
x:498 y:5, r:0 c:1
Moving 15.238.122.16  window
Moving window 88080398 to x:498 y:5 (size x:488 y:242)
x:991 y:5, r:0 c:2
Moving 15.238.122.17  window
Moving window 75497486 to x:991 y:5 (size x:488 y:242)
x:1484 y:5, r:0 c:3
Moving 15.238.122.18  window
Moving window 62914574 to x:1484 y:5 (size x:488 y:242)
x:1977 y:5, r:0 c:4
Moving 115.238.122.19  window
Moving window 83886094 to x:1977 y:5 (size x:488 y:242)
x:2470 y:5, r:0 c:5
Moving 15.238.122.20  window
Moving window 92274702 to x:2470 y:5 (size x:488 y:242)
x:5 y:252, r:1 c:0
Moving 15.238.122.22  window
Moving window 77594638 to x:5 y:252 (size x:488 y:242)
x:498 y:252, r:1 c:1
Moving 15.238.122.23  window
Moving window 67108878 to x:498 y:252 (size x:488 y:242)
x:991 y:252, r:1 c:2
Moving 15.238.122.24  window
Moving window 69206030 to x:991 y:252 (size x:488 y:242)
x:1484 y:252, r:1 c:3
Moving 15.238.122.25  window
Moving window 73400334 to x:1484 y:252 (size x:488 y:242)
x:1977 y:252, r:1 c:4
Moving 15.238.122.26  window
Moving window 71303182 to x:1977 y:252 (size x:488 y:242)
x:2470 y:252, r:1 c:5
Moving 15.238.122.27  window
Moving window 81788942 to x:2470 y:252 (size x:488 y:242)
x:5 y:499, r:2 c:0
Moving 15.238.122.29  window
Moving window 79691790 to x:5 y:499 (size x:488 y:242)
x:498 y:499, r:2 c:1
Moving 15.238.122.20  window
Moving window 94371854 to x:498 y:499 (size x:488 y:242)
x:991 y:499, r:2 c:2
Moving 15.238.122.21  window
Moving window 90177550 to x:991 y:499 (size x:488 y:242)
x:1484 y:499, r:2 c:3
Moving 15.238.122.22  window
Moving window 96469006 to x:1484 y:499 (size x:488 y:242)
x:1977 y:499, r:2 c:4
Moving 15.238.122.23  window
Moving window 85983246 to x:1977 y:499 (size x:488 y:242)
x:2470 y:499, r:2 c:5
Moving 15.238.122.24  window
Moving window 111149070 to x:2470 y:499 (size x:488 y:242)
Setting focus on 15.238.122.24
Setting focus on 15.238.122.23
Setting focus on 15.238.122.22
Setting focus on 15.238.122.21
Setting focus on 15.238.122.20
Setting focus on 15.238.122.29
Setting focus on 15.238.122.27
Setting focus on 15.238.122.26
Setting focus on 15.238.122.15
Setting focus on 15.238.122.24
Setting focus on 15.238.122.23
Setting focus on 15.238.122.22
Setting focus on 15.238.122.20
Setting focus on 15.238.122.19
Setting focus on 15.238.122.18
Setting focus on 15.238.122.17
Setting focus on 15.238.122.16
Setting focus on 15.238.122.15
Sending console to front

这是cssh的调试信息中与窗口重排相关的部分, 最后的Setting focus 提示了我, 当前是重排所有窗口后, 再把焦点逐个定位到每个窗口(相当于鼠标点中的窗口状态), 是否在KDE下没有做这一步就无法调整大小? 根据Setting focus, 我找到了cssh中 相关的代码

# Now remap in right order to get overlaps correct
    if ( $config{window_tiling_direction} =~ /right/i ) {
        foreach my $server ( reverse(@hosts) ) {
            logmsg( 2, "Setting focus on $server" );
            $xdisplay->req( 'MapWindow', $servers{$server}{wid} );

            # flush every time and wait a moment (The WMs are so slow...)
            $xdisplay->flush();
            select( undef, undef, undef, 0.1 );    # sleep for a mo
        }
    }
    else {
        foreach my $server (@hosts) {
            logmsg( 2, "Setting focus on $server" );
            $xdisplay->req( 'MapWindow', $servers{$server}{wid} );

            # flush every time and wait a moment (The WMs are so slow...)
            $xdisplay->flush();
            select( undef, undef, undef, 0.1 );    # sleep for a mo
        }
    }

不难看出, '$xdisplay->req( 'MapWindow', $servers{$server}{wid} );' 这一句就是我要的, $servers{$server}{wid} 就是窗口的ID, 依葫芦画瓢, 我加了这么一句到send_resizemove的函数调用之前

logmsg( 2, "Moving $server window" );
       $xdisplay->req( 'MapWindow', $servers{$server}{wid} );
        send_resizemove(
            $servers{$server}{wid},
            $current_x, $current_y,
            $config{internal_terminal_width},    #该参数指定了重排时窗口的新宽度
            $config{internal_terminal_height}    #该参数指定了重排时窗口的新高度
        );

很幸运的, 确实如我所想, 终于能在KDE下正确重排窗口了!!

2010-09-02 11:18466clusterssh