Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/09/2015, 16:29
susi141
 
Fecha de Ingreso: agosto-2011
Mensajes: 73
Antigüedad: 12 años, 9 meses
Puntos: 0
Pregunta Como obtener titulo y proceso de la ventana activa linux ?

Hola,

He logrado obtener en mi app el titulo y nombre del proceso de la ventana activa, lo logre utilizando este metodo:

Código C++:
Ver original
  1. #include <QCoreApplication>
  2. #include <QString>
  3. #include <QDebug>
  4. #include <string>
  5. #include <stdlib.h>
  6. #include <iostream>
  7. #include <stdio.h>
  8. #include <string>
  9. #include <unistd.h>
  10.  
  11. using namespace std;
  12.  
  13. inline std::string exec(char* cmd) {
  14.     FILE* pipe = popen(cmd, "r");
  15.     if (!pipe) return "ERROR";
  16.     char buffer[128];
  17.     std::string result = "";
  18.     while(!feof(pipe)) {
  19.         if(fgets(buffer, 128, pipe) != NULL)
  20.                 result += buffer;
  21.     }
  22.     pclose(pipe);
  23.     return result;
  24. }
  25.  
  26. int main(int argc, char *argv[]){
  27. QCoreApplication app(argc,argv);
  28. Qstring title = exec("xdotool getactivewindow getwindowname").c_str();
  29. QString name = exec("cat /proc/$(xdotool getwindowpid $(xdotool getwindowfocus))/comm").c_str();
  30.  return app.exec();
  31. }

Este funciona perfectamente, sin embargo necesito lograr hacer esto pero sin el cmd, osea sin tener q llamar al exec, hay alguna forma de hacerlo ??

Última edición por susi141; 14/09/2015 a las 06:24