@@ -382,6 +382,9 @@ def _clamp_to_screen(self, x, y):
382382 geo = scr .availableGeometry ()
383383 cx = max (geo .left (), min (x , geo .right () - self .width () + 1 ))
384384 cy = max (geo .top (), min (y , geo .bottom () - self .height () + 1 ))
385+ logger .debug (
386+ f"_clamp_to_screen: 输入({ x } , { y } ), 输出({ cx } , { cy } ), 屏幕区域: { geo } "
387+ )
385388 return cx , cy
386389
387390 def _create_container_layout (self ):
@@ -794,7 +797,6 @@ def _retract_into_edge(self):
794797 self ._retracted = True
795798
796799 def _expand_from_edge (self ):
797- # 基于当前屏幕可用区域展开
798800 fg = self .frameGeometry ()
799801 scr = QGuiApplication .screenAt (fg .center ()) or QApplication .primaryScreen ()
800802 geo = scr .availableGeometry ()
@@ -803,6 +805,7 @@ def _expand_from_edge(self):
803805 elif self .x () + self .width () > geo .right ():
804806 self .move (geo .right () - self .width () + 1 , self .y ())
805807 self ._retracted = False
808+ logger .debug (f"_expand_from_edge: 窗口位置已展开到 ({ self .x ()} , { self .y ()} )" )
806809
807810 def _check_edge_proximity (self ):
808811 """检测窗口是否靠近屏幕边缘,并实现贴边隐藏功能(带动画效果)"""
@@ -850,9 +853,9 @@ def _check_edge_proximity(self):
850853 # 设置动画起始值(当前位置)
851854 self .animation .setStartValue (self .geometry ())
852855
853- # 设置动画结束值(隐藏位置)- 完全移出屏幕
856+ # 设置动画结束值(隐藏位置)- 移出屏幕但保留部分在屏幕内以保持screenAt()正常工作
854857 end_rect = QRect (
855- - window_width ,
858+ screen . left () - window_width + 1 ,
856859 window_pos .y (),
857860 window_width ,
858861 window_height ,
@@ -893,9 +896,9 @@ def on_animation_finished():
893896 # 设置动画起始值(当前位置)
894897 self .animation .setStartValue (self .geometry ())
895898
896- # 设置动画结束值(隐藏位置)- 完全移出屏幕
899+ # 设置动画结束值(隐藏位置)- 移出屏幕但保留部分在屏幕内以保持screenAt()正常工作
897900 end_rect = QRect (
898- screen .width () ,
901+ screen .right () - 1 ,
899902 window_pos .y (),
900903 window_width ,
901904 window_height ,
@@ -1133,15 +1136,15 @@ def _expand_window(self):
11331136 if storage_pos .x () < screen .width () // 2 :
11341137 # 左侧收纳浮窗,向右移出屏幕
11351138 storage_end_rect = QRect (
1136- screen .width () ,
1139+ screen .right () - 1 ,
11371140 storage_pos .y (),
11381141 storage_width ,
11391142 storage_height ,
11401143 )
11411144 else :
11421145 # 右侧收纳浮窗,向左移出屏幕
11431146 storage_end_rect = QRect (
1144- - storage_width ,
1147+ screen . left () - storage_width + 1 ,
11451148 storage_pos .y (),
11461149 storage_width ,
11471150 storage_height ,
@@ -1242,6 +1245,7 @@ def _create_arrow_button(self, direction, x, y):
12421245 self .arrow_widget = DraggableWidget ()
12431246 self .arrow_widget .setFixedSize (30 , 30 )
12441247 self .arrow_widget .move (x , y )
1248+ self .arrow_widget .setFixedX (x )
12451249 self .arrow_widget .setWindowFlags (
12461250 Qt .FramelessWindowHint
12471251 | Qt .WindowStaysOnTopHint
@@ -1322,6 +1326,10 @@ def new_mouse_release(event):
13221326
13231327 def _show_hidden_window (self , direction ):
13241328 """显示隐藏的窗口(带动画效果)"""
1329+ logger .debug (
1330+ f"_show_hidden_window: 方向={ direction } , 当前窗口位置=({ self .x ()} , { self .y ()} )"
1331+ )
1332+
13251333 # 如果有正在进行的动画,先停止它
13261334 if (
13271335 hasattr (self , "animation" )
@@ -1331,6 +1339,7 @@ def _show_hidden_window(self, direction):
13311339
13321340 # 获取屏幕尺寸
13331341 screen = QApplication .primaryScreen ().availableGeometry ()
1342+ logger .debug (f"_show_hidden_window: 屏幕区域={ screen } " )
13341343
13351344 # 获取窗口当前位置和尺寸
13361345 window_width = self .width ()
@@ -1378,6 +1387,9 @@ def _show_hidden_window(self, direction):
13781387
13791388 # 启动动画
13801389 self .animation .start ()
1390+ logger .debug (
1391+ f"_show_hidden_window: 动画已启动,目标位置=({ end_rect .x ()} , { end_rect .y ()} )"
1392+ )
13811393
13821394 # 删除箭头按钮
13831395 self ._delete_arrow_button ()
@@ -1552,40 +1564,23 @@ def mousePressEvent(self, event):
15521564 self ._long_press_timer .start (self ._long_press_duration )
15531565
15541566 def mouseMoveEvent (self , event ):
1555- """鼠标移动事件"""
1556- if event .buttons () & Qt .LeftButton : # 确保左键按下
1567+ """鼠标移动事件 - 只允许在y轴移动,x轴位置固定 """
1568+ if event .buttons () & Qt .LeftButton :
15571569 current_time = QDateTime .currentMSecsSinceEpoch ()
1558- # 检查是否已经长按或者移动距离足够大
15591570 if self ._long_press_triggered or (
15601571 current_time - self ._press_start_time > 100
15611572 and abs (event .globalY () - self ._drag_start_y ) > 5
15621573 ):
15631574 if not self ._dragging :
15641575 self ._dragging = True
1565- # 设置拖动标志,表示发生了拖动操作
15661576 self ._was_dragging = True
15671577 self .setCursor (Qt .ClosedHandCursor )
1568- # 如果还没触发长按,停止计时器
15691578 if not self ._long_press_triggered :
15701579 self ._long_press_timer .stop ()
15711580
1572- # 计算新的y坐标
15731581 new_y = self ._original_y + (event .globalY () - self ._drag_start_y )
1574- # 保持x坐标不变
15751582 self .move (self ._fixed_x , new_y )
15761583
1577- # 同时更新主窗口的位置
1578- if (
1579- hasattr (self , "parent" )
1580- and self .parent ()
1581- and hasattr (self .parent (), "move" )
1582- ):
1583- # 获取主窗口的当前位置
1584- parent_x = self .parent ().x ()
1585- parent_y = self .parent ().y ()
1586- # 更新主窗口的y坐标,保持x坐标不变
1587- self .parent ().move (parent_x , new_y )
1588-
15891584 def mouseReleaseEvent (self , event ):
15901585 """鼠标释放事件"""
15911586 if event .button () == Qt .LeftButton :
0 commit comments