Bug 46966 - B2 decoration sticky pin bugs'n fix
Summary: B2 decoration sticky pin bugs'n fix
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: decorations (show other bugs)
Version: unspecified
Platform: unspecified Other
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-08-25 21:03 UTC by Volker Schatz
Modified: 2003-09-30 20:20 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bugzilla Maintainers 2002-08-25 20:58:45 UTC
(*** This bug was imported into bugs.kde.org ***)

Package: kwin
Version: 3.0.1
Severity: normal
System: Mandrake Linux 8.1
Kernel: 2.2.17-21mdksecure

...and another one.

Problems:
(Select B II decoration first.)
1) Click on the pin to make window sticky then use window operations menu
to make it unsticky.  The pin will remain down even though the sticky
property works correctly.  The only way to get it up again is to repeat
the procedure above.
2) Press and hold mouse button on pin of non-sticky window and switch to a
different workspace (eg Ctrl_tab) with the mouse button still down.
Release the mouse button and return to the previous workspace - the pin is
still down but sticky is not set (which is correct).

Reason:
1) B II is the only decoration which uses a toggle button for the sticky
symbol.  The problem comes from a confusion between "down" and "on" state
of a toggle button.  Contrary to what the QButton documentation says a
toggle button is in "down" state when it is "on" not just when the user
holds down the mouse button.  When a window is made (un)sticky with the
menu B2Client::stickyChange() sets it down manually.  This causes "on"
and "down" to get out of sync so that "on" is true whenever "down" is not.
Since B2Button::drawButton() draws a pin-down when either is true it is
always displayed as down.
2) This bug applies to all window buttons of several (probably all)
decorations.  When a window is hidden while the mouse button is pressed
down a QButton apparently remains in "down" state.  For buttons other
than B II's sticky button this is more of a wishlist item - just
aesthetics.  And of course few people will hold down buttons while
switching workspaces.

Fix:
1) Below the simpler (in terms of code length and CPU usage ;)) solution.
Relies on the fact that Qt behaves as it does not as it says it does.
"down" property is used exclusively (since all the pixmaps and other stuff
are called "...down").  Alternative: leave drawButton() as it is and
replace all calls of QButton::setDown(...) by conditional:
if( ... != QButton::isOn() )  QButton::toggle()
(since QButton::setOn() is protected).
2) Reset "down" state of all buttons and set "down" state of pin according
to sticky flag.  Did this below for B II (last but one diff chunk).  Up to
you to decide whether it's worth the trouble for the others.


    Ciao Volker



*** kdebase-3.0.1/kwin/clients/b2/b2client_orig.cpp     Sun Aug 25 18:54:34 2002
--- kdebase-3.0.1/kwin/clients/b2/b2client.cpp  Sun Aug 25 22:12:22 2002
***************
*** 161167 ****
      }
      else{
          if(client->isActive()){
!             if(isOn() || isDown())
                  p->drawPixmap((width()-pDown->width())/2
                                (height()-pDown->height())/2 *pDown);
              else
--- 161167 ----
      }
      else{
          if(client->isActive()){
!             if(isDown())
                  p->drawPixmap((width()-pDown->width())/2
                                (height()-pDown->height())/2 *pDown);
              else
***************
*** 169175 ****
                                (height()-pNorm->height())/2 *pNorm);
          }
          else{
!             if(isOn() || isDown())
                  p->drawPixmap((width()-pDown->width())/2
                                (height()-pDown->height())/2 *iDown);
              else
--- 169175 ----
                                (height()-pNorm->height())/2 *pNorm);
          }
          else{
!             if(isDown())
                  p->drawPixmap((width()-pDown->width())/2
                                (height()-pDown->height())/2 *iDown);
              else
***************
*** 666671 ****
--- 666676 ----

  void B2Client::showEvent(QShowEvent *ev)
  {
+     int i;
+     for( i= 0; i < BtnCount; ++i )
+         if( button[i] )
+             button[i]->setDown(false);
+     button[BtnSticky]->setDown(isSticky());
      calcHiddenButtons();
      Client::showEvent(ev);
      doShape();
***************
*** 748753 ****
--- 753760 ----
  {
      if (button[BtnSticky]) {
          button[BtnSticky]->setDown(on);
+         // This destroys the synchronisation between "on" and "down" properties
+         // of a toggle QButton so don't EVER use isOn() with the sticky button.
          button[BtnSticky]->setTipText(on ? i18n("Un-Sticky") : i18n("Sticky"));
      }
  }
Comment 1 Luciano Montanaro 2003-09-30 20:20:06 UTC
I applied the first fix, substantially. I can't reproduce the second problem with current cvs with 
B2 or any other decoration, so I think that part of the problem has been fixed too.