How to add touchpad and battery for notebooks

Ludwig Cornelius t_d_l_c at gmx.de
Thu Apr 5 09:38:30 UTC 2018


Hi dear mailing list,


I want to add the widgets for touchpad and battery on notebooks 
automatically by using a script or configuration file. Is this possible?


In plasma 4 we had a js file that would do this.  I tried to adopt it 
for plasma 5, but while it seems to do the right thing (at least for one 
widget) when using the interactive console, there seem problems when 
executing it during login by putting it in 
/usr/share/plasma/shells/org.kde.plasma.desktop/contents/updates/.

The ~/.config/plasma-org.kde.plasma.desktop-appletsrc doesn't contain 
all necessary entries, probably because they are not there yet to be 
updated by my script (new home).

So is there another way to activate touchpad/battery?

Best wishes,

Ludwig


P.S. - this is my script:


function objToString(myobj) {
     result = ""
     for(var propName in myobj) {
         propValue = myobj[propName]
         result = result + propName + " " + propValue + "\n";
     }
     return result;
}


function l(level, message) {
     if (level >= 0) print(message)
}


function getFreeSlotFor(usedIndexesArray) {
         //find free slot
         l(0, "usedIndexesArray: " + usedIndexesArray);
         var freeSlot=-1;
         for (j=0; j<300; j++) {
           var foundValue = -1;
           for(k=0; k<usedIndexesArray.length; k++) {
             if(j == usedIndexesArray[k]) foundValue = 1;
           }
           if (foundValue == -1) {
             freeSlot = j;
         break;
           }
         }

         l(0, "freeSlot is " + freeSlot);
     return freeSlot;

}

function addWidgetToSystray (widgetName) {

   try {
     l(0, "---------------------- " + arguments.callee.name + " " + 
widgetName);

     //sleep(12000);
     pids = panelIds;
     for (i = 0; i < pids.length; ++i) { //search through the panels
       panel = panelById(pids[i]);
       if (!panel) continue;

         //l(0, objToString(panel))

         systemtrayId = -1;
         // check if widget already in panel and determine id of 
org.kde.plasma.systemtray
         for (tmpIndex = 0; tmpIndex < panel.widgetIds.length; tmpIndex 
++) {
             appletWidget = panel.widgetById(panel.widgetIds[tmpIndex]);
             // l(0, appletWidget.type);
             if (appletWidget.type == widgetName) {
                 l(1, widgetName + " already in panel");
                 return;
             }
             else if (appletWidget.type == "org.kde.plasma.systemtray") {
                 systemtrayId = panel.widgetIds[tmpIndex];
                 l(0, "systemtrayId is " + systemtrayId);
             }
         }


         // find free slot, write to config
         freeSlot = getFreeSlotFor(panel.widgetIds);
         if (freeSlot == -1) {
             l(3, "No freeSlot found");
             return;
         }
         //write applet plugin to config
         if (freeSlot > -1) {
             l(0, "will write to config: applet " + widgetName + " in 
freeSlot " + freeSlot);
             panel.currentConfigGroup = new Array("Applets", freeSlot);
             panel.writeConfig("plugin", widgetName);
             panel.writeConfig("immutability", 1);
             panel.reloadConfig();
         }

         //sleep(5000)

         //write AppletOrder
         panel.currentConfigGroup = new Array("General");
         currOrder = panel.readConfig("AppletOrder");
         newOrder = "";
         if (currOrder == "" ) newOrder = freeSlot;
         else {

             tmpIdArray = currOrder.split(";");
             for (j=0; j<tmpIdArray.length; j++) {
                 nextNum = tmpIdArray[j];
                 if (nextNum == systemtrayId) newOrder += freeSlot + ";";
                 newOrder += nextNum;
                 if (j != (tmpIdArray.length -1) ) newOrder += ";" ;
             }
         }
         l(0, "currOrder is " + currOrder);
         l(0, "newOrder is " + newOrder);
         panel.writeConfig("AppletOrder", newOrder);

         return;

     }

   }
   catch (err) {
     print("20-addTouchpadDisabler.js: " + err.message);
   }

}

addWidgetToSystray("touchpad");
addWidgetToSystray("org.kde.plasma.battery");




More information about the Enterprise mailing list