~vanvugt/compiz/fix-1015898

« back to all changes in this revision

Viewing changes to src/event.cpp

  • Committer: Daniel van Vugt
  • Date: 2012-06-05 08:44:00 UTC
  • mfrom: (3237.1.2 fix-1005569.3)
  • Revision ID: daniel.van.vugt@canonical.com-20120605084400-v627i0spuiz3mynk
Fix up a few issues thumper pointed out in the fixes for LP: #1005569.

  * Use else instead of unconditional reset (makes the first call faster,
    but all others slower, negligibly)
  * Don't mask locals by reusing the same name
  * Remember to reset arg[7] for XkbStateNotify
  * Check for NULL strings. Don't dereference them, just treat as empty.

Show diffs side-by-side

added added

removed removed

Lines of Context:
662
662
        o[4].setName ("y", CompOption::TypeInt);
663
663
        o[5].setName ("root", CompOption::TypeInt);
664
664
    }
665
 
    o[6].reset ();
666
 
    o[7].reset ();
 
665
    else
 
666
    {
 
667
        o[6].reset ();
 
668
        o[7].reset ();
 
669
    }
667
670
 
668
671
    switch (event->type) {
669
672
    case ButtonPress:
941
944
        if (event->type == xkbEvent.get())
942
945
        {
943
946
            XkbAnyEvent *xkbEvent = (XkbAnyEvent *) event;
944
 
            static CompOption::Vector o;
 
947
            static CompOption::Vector arg;
945
948
 
946
 
            if (o.empty ())
 
949
            if (arg.empty ())
947
950
            {
948
 
                o.resize (8);
949
 
                o[0].setName ("event_window", CompOption::TypeInt);
950
 
                o[1].setName ("window", CompOption::TypeInt);
 
951
                arg.resize (8);
 
952
                arg[0].setName ("event_window", CompOption::TypeInt);
 
953
                arg[1].setName ("window", CompOption::TypeInt);
951
954
            }
952
955
 
953
956
            if (xkbEvent->xkb_type == XkbStateNotify)
954
957
            {
955
958
                XkbStateNotifyEvent *stateEvent = (XkbStateNotifyEvent *) event;
956
959
 
957
 
                o[0].value ().set ((int) orphanData.activeWindow);
958
 
                o[1].value ().set ((int) orphanData.activeWindow);
959
 
                o[2].setName ("modifiers", CompOption::TypeInt);
960
 
                o[2].value ().set ((int) stateEvent->mods);
961
 
                o[3].setName ("time", CompOption::TypeInt);
962
 
                o[3].value ().set ((int) xkbEvent->time);
963
 
                o[7].value ().set ((int) xkbEvent->time);
 
960
                arg[0].value ().set ((int) orphanData.activeWindow);
 
961
                arg[1].value ().set ((int) orphanData.activeWindow);
 
962
                arg[2].setName ("modifiers", CompOption::TypeInt);
 
963
                arg[2].value ().set ((int) stateEvent->mods);
 
964
                arg[3].setName ("time", CompOption::TypeInt);
 
965
                arg[3].value ().set ((int) xkbEvent->time);
 
966
                arg[7].value ().set ((int) xkbEvent->time);
964
967
 
965
968
                if (stateEvent->event_type == KeyPress)
966
969
                    eventManager.resetPossibleTap();
968
971
                foreach (CompPlugin *p, CompPlugin::getPlugins ())
969
972
                {
970
973
                    CompOption::Vector &options = p->vTable->getOptions ();
971
 
                    if (triggerStateNotifyBindings (options, stateEvent, o))
 
974
                    if (triggerStateNotifyBindings (options, stateEvent, arg))
972
975
                        return true;
973
976
                }
974
977
            }
975
978
            else if (xkbEvent->xkb_type == XkbBellNotify)
976
979
            {
977
 
                o[0].value ().set ((int) orphanData.activeWindow);
978
 
                o[1].value ().set ((int) orphanData.activeWindow);
979
 
                o[2].setName ("time", CompOption::TypeInt);
980
 
                o[2].value ().set ((int) xkbEvent->time);
981
 
                o[3].reset ();
 
980
                arg[0].value ().set ((int) orphanData.activeWindow);
 
981
                arg[1].value ().set ((int) orphanData.activeWindow);
 
982
                arg[2].setName ("time", CompOption::TypeInt);
 
983
                arg[2].value ().set ((int) xkbEvent->time);
 
984
                arg[3].reset ();
 
985
                arg[7].reset ();
982
986
 
983
987
                foreach (CompPlugin *p, CompPlugin::getPlugins ())
984
988
                {
985
989
                    CompOption::Vector &options = p->vTable->getOptions ();
986
 
                    if (triggerBellNotifyBindings (options, o))
 
990
                    if (triggerBellNotifyBindings (options, arg))
987
991
                        return true;
988
992
                }
989
993
            }