@@ -25,6 +25,7 @@ DGUI_USE_NAMESPACE
2525CScreenshotWidget::CScreenshotWidget (CPickerManager *parent): QWidget(nullptr ),
2626 _parentManager(parent)
2727{
28+ qDebug () << " Initializing screenshot widget" ;
2829 // 为顶层窗口
2930 this ->setWindowFlags (this ->windowFlags () | Qt::Window | Qt::FramelessWindowHint
3031 | Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint);
@@ -58,6 +59,7 @@ void CScreenshotWidget::keyPressEvent(QKeyEvent *event)
5859{
5960 // wayland下 DRegionMonitor::keyPress会失效,这里会响应
6061 if (event->matches (QKeySequence::Cancel)) {
62+ qDebug () << " Escape key pressed, exiting application" ;
6163 QApplication::quit ();
6264 }
6365 QWidget::keyPressEvent (event);
@@ -81,11 +83,13 @@ void CScreenshotWidget::wheelEvent(QWheelEvent *event)
8183
8284CPickerManager::CPickerManager (): QObject(nullptr )
8385{
86+ qDebug () << " Initializing color picker manager" ;
8487 const int windowHeight = 236 ;
8588 const int windowWidth = 236 ;
8689 qreal radio = qApp->devicePixelRatio ();
8790 _shadowPixmap = QPixmap (Utils::getQrcPath (" shadow.png" ));
8891 if (isWaylandPlatform ()) {
92+ qDebug () << " Running on Wayland platform" ;
8993 _shadowPixmap = _shadowPixmap.scaled (windowWidth, windowHeight);
9094 } else {
9195 _shadowPixmap = _shadowPixmap.scaled (windowWidth / radio, windowHeight / radio, Qt::KeepAspectRatio, Qt::SmoothTransformation);
@@ -98,11 +102,12 @@ CPickerManager::CPickerManager(): QObject(nullptr)
98102 eventMonitor->setWatchedRegion (QRegion (INT_MIN, INT_MIN, INT_MAX * 2 , INT_MAX * 2 ));
99103
100104 QObject::connect (eventMonitor, &DRegionMonitor::keyPress, this , [ = ](const QString & name) {
101- if (name == " Escape" )
105+ if (name == " Escape" ) {
106+ qDebug () << " Escape key detected from region monitor, exiting application" ;
102107 QApplication::quit ();
108+ }
103109 });
104110
105-
106111 // Binding handler to xrecord signal.
107112 QObject::connect (eventMonitor, &DRegionMonitor::cursorMove, this , [ = ](const QPoint & p) {
108113 onMouseMove (p);
@@ -115,7 +120,7 @@ CPickerManager::CPickerManager(): QObject(nullptr)
115120 eventMonitor->registerRegion ();
116121
117122 if (!eventMonitor->registered ()) {
118- qWarning () << " Failed on register monitor" ;
123+ qWarning () << " Failed to register region monitor, exiting application " ;
119124 QApplication::quit ();
120125 }
121126 ensureDeskTopPixmap ();
@@ -124,18 +129,19 @@ CPickerManager::CPickerManager(): QObject(nullptr)
124129 _updateScreenshotTimer->setSingleShot (true );
125130 connect (_updateScreenshotTimer, SIGNAL (timeout ()), this , SLOT (handleMouseMove ()));
126131
127-
128132 QPixmap pix (16 , 16 );
129133 pix.fill (Qt::transparent);
130134 qApp->setOverrideCursor (QCursor (pix));
131135}
132136
133137CPickerManager::~CPickerManager ()
134138{
139+ qDebug () << " Destroying color picker manager" ;
135140}
136141
137142void CPickerManager::setLanchFlag (CPickerManager::ELanchType tp, const QString &appName)
138143{
144+ qDebug () << " Setting launch flag:" << tp << " for application:" << appName;
139145 _isLaunchByDBus = tp;
140146 if (_isLaunchByDBus == ELanchedByOtherApp)
141147 _appid = appName;
@@ -153,6 +159,7 @@ void CPickerManager::setLanchFlag(CPickerManager::ELanchType tp, const QString &
153159
154160void CPickerManager::StartPick (const QString &id)
155161{
162+ qDebug () << " Starting color pick with ID:" << id;
156163 _appid = id;
157164}
158165
@@ -174,11 +181,14 @@ void CPickerManager::onMousePress(const QPoint &p, const int flag)
174181 // wayland触摸屏下的点击是DRegionMonitor::Button_Middle,鼠标左键点击DRegionMonitor::Button_Left。无法区分是鼠标左键还是触摸屏,故支持中键点击
175182 // 最佳方案是TDK将触摸屏点击修改成左键点击。。。。。。。
176183 if (button != DRegionMonitor::Button_Left && button != DRegionMonitor::Button_Middle) {
184+ qDebug () << " Ignoring non-left/middle button press on Wayland" ;
177185 return ;
178186 }
179187 } else {
180- if (button != DRegionMonitor::Button_Left)
188+ if (button != DRegionMonitor::Button_Left) {
189+ qDebug () << " Ignoring non-left button press" ;
181190 return ;
191+ }
182192 }
183193
184194 // 立即更新坐标
@@ -194,12 +204,15 @@ void CPickerManager::onMousePress(const QPoint &p, const int flag)
194204
195205 // Rest color type to hex if config file not exist.
196206 Settings settings;
207+ QString colorType = settings.getOption (" color_type" , " HEX" ).toString ();
208+ qDebug () << " Color picked:" << _curColor.name () << " in format:" << colorType;
197209
198210 // Emit copyColor signal to copy color to system clipboard.
199- copyColor (_curColor, settings. getOption ( " color_type " , " HEX " ). toString () );
211+ copyColor (_curColor, colorType );
200212
201213 // Send colorPicked signal when call by DBus and no empty appid.
202214 if (_appid != " " ) {
215+ qDebug () << " Sending color picked signal to application:" << _appid;
203216 colorPicked (_appid, Utils::colorToHex (_curColor));
204217 }
205218 }
@@ -213,13 +226,15 @@ void CPickerManager::handleMouseMove()
213226
214227void CPickerManager::initShotScreenWidgets ()
215228{
229+ qDebug () << " Initializing screen shot widgets" ;
216230 ensureDeskTopPixmap ();
217231 auto screens = QApplication::screens ();
218232 // 去出复制屏
219233 int i = 0 ;
220234 while (i < screens.size ()) {
221235 for (int j = screens.size () - 1 ; j > i; j--) {
222236 if (screens.at (i)->geometry ().topLeft () == screens.at (j)->geometry ().topLeft ()) {
237+ qDebug () << " Removing duplicate screen at index:" << j;
223238 screens.removeAt (j);
224239 }
225240 }
@@ -228,7 +243,6 @@ void CPickerManager::initShotScreenWidgets()
228243
229244 foreach (auto screen, screens) {
230245 auto pix = getScreenShotPixmap (screen);
231- // auto geometry = QRect(screen->geometry().topLeft(), screen->geometry().size() * screen->devicePixelRatio());
232246 CScreenshotWidget *pWidget = new CScreenshotWidget (this );
233247 pWidget->setPixmap (pix);
234248 pWidget->setGeometry (screen->geometry ());
@@ -245,6 +259,7 @@ void CPickerManager::initShotScreenWidgets()
245259
246260 // 解决 wayland 下调出取色器后点击 Esc 无法退出取色器
247261 if (isWaylandPlatform ()) {
262+ qDebug () << " Setting up Wayland-specific window activation" ;
248263 // 延迟 200ms 后取得当前背景窗口的焦点,用以捕获 Esc 按键退出
249264 QTimer::singleShot (200 , this , [ = ]() {
250265 auto currentWidget = _widgets.value (qApp->screenAt (QCursor::pos ()));
@@ -324,27 +339,16 @@ void CPickerManager::updateCursor(const QPixmap &pixMap, const QPoint &posInPixm
324339
325340 _curColor = focusPixmap.toImage ().pixelColor (focusPixmap.rect ().center ());
326341
327- // painter.setPen(QColor(255, 0, 0, 100));
328- // QFont f;
329- // painter.setFont(f);
330- // QString text = _curColor.name() + QString("w=%1lw=%2").arg(focusPixmap.width()).arg(logicPixelWidth);
331- // QSize colorNameSz = QSize(QFontMetrics(f).width(text), QFontMetrics(f).height()) ;
332-
333- // QRectF colorNameRect = QRectF(QPointF((cursorPix.width() - colorNameSz.width()) / 2,
334- // (cursorPix.height() - colorNameSz.height()) / 2 + colorNameSz.height() + 6), colorNameSz);
335- // painter.drawText(colorNameRect, text);
336-
337342 // 设置当前窗口鼠标样式
338343 _cursorPix = cursorPix;
339344 this ->autoUpdate ();
340-
341345 }
342346}
343347
344-
345348void CPickerManager::ensureDeskTopPixmap ()
346349{
347350 if (_desktopPixmapDirty) {
351+ qDebug () << " Updating desktop pixmap" ;
348352 _desktopPixmap = getDesktopPixmap ();
349353 _desktopPixmapDirty = false ;
350354 }
@@ -368,18 +372,19 @@ QRect getDeskTopRect()
368372 QRect deskTopRect (0 , 0 , 0 , 0 );
369373 auto screens = QApplication::screens ();
370374 foreach (auto screen, screens) {
371-
372375 auto geometry = QRect (screen->geometry ().topLeft (), screen->geometry ().size () *
373376 screen->devicePixelRatio ());
374377 deskTopRect = deskTopRect.united (geometry);
375378 }
376379 return deskTopRect;
377380}
381+
378382QPixmap CPickerManager::getDesktopPixmap ()
379383{
380384 QPixmap result;
381385 bool iswayLand = isWaylandPlatform ();
382386 if (iswayLand) {
387+ qDebug () << " Getting desktop pixmap via KWin DBus interface" ;
383388 QPixmap res;
384389 QDBusInterface kwinInterface (QStringLiteral (" org.kde.KWin" ),
385390 QStringLiteral (" /Screenshot" ),
@@ -392,6 +397,7 @@ QPixmap CPickerManager::getDesktopPixmap()
392397 }
393398 result = res;
394399 } else {
400+ qDebug () << " Getting desktop pixmap via screen grab" ;
395401 QPixmap pixs (getDeskTopRect ().size ());
396402 pixs.fill (Qt::transparent);
397403 QPainter painter (&pixs);
0 commit comments