Subversion Repositories Kolibri OS

Rev

Rev 8389 | Rev 9453 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #define MEMSIZE 1024*80
  2.  
  3. //===================================================//
  4. //                                                   //
  5. //                       LIB                         //
  6. //                                                   //
  7. //===================================================//
  8.  
  9. #include "../lib/gui.h"
  10. #include "../lib/list_box.h"
  11. #include "../lib/io.h"
  12. #include "../lib/collection.h"
  13. #include "../lib/patterns/restart_process.h"
  14.  
  15. #include "../lib/mem.h"
  16.  
  17. #include "../lib/obj/libini.h"
  18.  
  19. //===================================================//
  20. //                                                   //
  21. //                       DATA                        //
  22. //                                                   //
  23. //===================================================//
  24.  
  25. int current_process_id = 0;
  26. int proc_list[256];
  27. collection attached=0;
  28.  
  29. llist list;
  30.  
  31. _ini ini = { "/sys/settings/appicons.ini", "icons"};
  32.  
  33. proc_info Form;
  34. proc_info Process;
  35.  
  36. enum {
  37.         ATTACHEMENT_BOTTOM,
  38.         ATTACHEMENT_LEFT,
  39.         ATTACHEMENT_TOP,
  40.         ATTACHEMENT_RIGHT
  41. };
  42. int attachement = ATTACHEMENT_BOTTOM;
  43.  
  44. #define CELLW 40
  45. #define CELLH 40
  46.  
  47. dword COLOR_BG      = 0x3B3B3B;
  48. dword COLOR_MENU_BG = 0x323232;
  49. dword COLOR_OPENED  = 0x999999;
  50. dword COLOR_ACTIVE  = 0x0099FF;
  51. dword COLOR_TEXT    = 0xFFFfff;
  52.  
  53.  
  54. //===================================================//
  55. //                                                   //
  56. //                       CODE                        //
  57. //                                                   //
  58. //===================================================//
  59.  
  60. void main()
  61. {
  62.         int btn;
  63.         load_dll(libini, #lib_init,1);
  64.  
  65.         ini_get_int stdcall ("/sys/appicons.ini", "taskbar", "attachement", ATTACHEMENT_BOTTOM);
  66.         attachement = EAX;
  67.  
  68.         SetAttachement();
  69.         GetAttachedItems();
  70.        
  71.         GetProcessInfo(#Form, SelfInfo);
  72.         SetWindowLayerBehaviour(-1, ZPOS_DESKTOP);
  73.         SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
  74.         loop() switch(@WaitEventTimeout(50))
  75.         {
  76.                 case evMouse:
  77.                         if (!CheckActiveProcess(Form.ID)) break;
  78.                         mouse.get();
  79.                         if (mouse.down) {}
  80.                         //if (list.ProcessMouse()) DrawProcessList();
  81.                         break;
  82.                 case evKey:
  83.                         GetKeys();
  84.                         if (key_scancode == SCAN_CODE_ESC) {
  85.                                 RunProgram(#program_path, NULL);
  86.                                 ExitProcess();
  87.                         }
  88.                         break;
  89.                 case evButton:
  90.                         btn = @GetButtonID();
  91.                         btn -= 100;
  92.                         if (btn < attached.count) RunProgram(attached.get(btn), NULL);
  93.                         else EventSetActiveProcess(btn);
  94.                         break;
  95.                 case evReDraw:
  96.                         DefineUnDragableWindow(NULL, NULL, NULL, NULL);
  97.                         list.SetSizes(0, 0, Form.width+1, Form.height+2, CELLH);
  98.                 default:
  99.                         DrawProcessList();
  100.         }
  101. }
  102.  
  103.  
  104. void GetProcessList()
  105. {
  106.         int i, j;
  107.         list.count=0;
  108.  
  109.         for (i=0; i<attached.count; i++)
  110.         {
  111.                 proc_list[list.count] = 0;
  112.                 list.count++;
  113.         }
  114.  
  115.         for (i=0; i<MAX_PROCESS_COUNT; i++)
  116.         {
  117.                 GetProcessInfo(#Process, i);
  118.                 if (Process.name)
  119.                 {
  120.                         for (j=0; j<11; j++) if (Process.name[j]!=' ') {                               
  121.                                 //do not show system process
  122.                                 if (Process.name[0]=='@') break;
  123.                                 if (!strcmp(#Process.name, "IDLE")) break;
  124.                                 if (!strcmp(#Process.name, "OS")) break;
  125.                                 if (!Process.width) && (!Process.height) break;
  126.                                 proc_list[list.count] = i;
  127.                                 list.count++;
  128.                                 break;
  129.                         }
  130.                 }
  131.         }
  132. }
  133.  
  134. void DrawProcessList()
  135. {
  136.         #define ACTIVE_SIZE 3
  137.         #define CELL_MARGIN_X 10
  138.         #define CELL_MARGIN_Y 4
  139.         #define CELL_PADDING 4
  140.         int i;
  141.         int posy=list.y;
  142.         int posx=list.x;
  143.         int icon_n;
  144.         dword status_color;
  145.  
  146.         GetProcessList();
  147.  
  148.         for (i=0; i<list.count; i++)
  149.         {
  150.                 if (proc_list[i+list.first]==0) {
  151.                         status_color = COLOR_BG;
  152.                         icon_n = ini.GetInt(attached.get(i+list.first)+strrchr(attached.get(i+list.first),'/'), 2);
  153.                 }
  154.                 else {
  155.                         GetProcessInfo(#Process, proc_list[i+list.first]);
  156.                         strlwr(#Process.name);
  157.                         icon_n = ini.GetInt(#Process.name, 2);
  158.                         if (CheckActiveProcess(Process.ID)) && (Process.status_window!=2) {
  159.                                 current_process_id = Process.ID;
  160.                                 status_color = COLOR_ACTIVE;
  161.                         }
  162.                         else {
  163.                                 status_color = COLOR_OPENED;
  164.                         }                      
  165.                 }
  166.                 DrawWideRectangle(posx, posy, 40, 40, CELL_PADDING, COLOR_BG);
  167.                 DefineButton(posx, posy, CELLW-1, CELLH, 100+i+BT_HIDE+BT_NOFRAME, NULL);
  168.                 draw_icon_32(posx+CELL_PADDING, posy+CELL_PADDING, COLOR_BG, icon_n);
  169.  
  170.                 if (ATTACHEMENT_BOTTOM==attachement) DrawBar(posx, posy+CELLH-ACTIVE_SIZE, CELLW, ACTIVE_SIZE, status_color);
  171.                 if (ATTACHEMENT_LEFT  ==attachement) DrawBar(posx, posy, ACTIVE_SIZE, CELLH, status_color);
  172.                 if (ATTACHEMENT_TOP   ==attachement) DrawBar(posx, posy, CELLW, ACTIVE_SIZE, status_color);
  173.                 if (ATTACHEMENT_RIGHT ==attachement) DrawBar(posx+CELLW-ACTIVE_SIZE, posy, ACTIVE_SIZE, CELLH, status_color);
  174.  
  175.                 if (ATTACHEMENT_TOP==attachement) || (ATTACHEMENT_BOTTOM==attachement) {
  176.                         posx += CELLW;
  177.                         DrawBar(posx, posy, CELL_MARGIN_X, list.h, COLOR_BG);
  178.                         posx += CELL_MARGIN_X;
  179.                 }
  180.                 if (ATTACHEMENT_LEFT==attachement) || (ATTACHEMENT_RIGHT==attachement) {
  181.                         posy += CELLH;
  182.                         DrawBar(posx, posy, list.w, CELL_MARGIN_Y, COLOR_BG);
  183.                         posy += CELL_MARGIN_Y;
  184.                 }
  185.         }
  186.         DrawBar(posx, posy, list.w, list.h, COLOR_BG);
  187. }
  188.  
  189. void SetAttachement()
  190. {
  191.         if (attachement==ATTACHEMENT_LEFT) {
  192.                 DefineUnDragableWindow(0, 0, CELLW-1, screen.height);
  193.                 SetClientScreenArea(CELLW, screen.width-CELLW, 0, screen.height);
  194.         }
  195.         if (attachement==ATTACHEMENT_RIGHT) {
  196.                 DefineUnDragableWindow(screen.width - CELLW, 0, CELLW, screen.height);
  197.                 SetClientScreenArea(0, screen.width-CELLW, 0, screen.height);
  198.         }
  199.         if (attachement==ATTACHEMENT_TOP) {
  200.                 DefineUnDragableWindow(0, 0, screen.width, CELLH-1);
  201.                 SetClientScreenArea(0, 0, CELLH, screen.height);
  202.         }
  203.         if (attachement==ATTACHEMENT_BOTTOM) {
  204.                 DefineUnDragableWindow(0, screen.height, screen.width, CELLH);
  205.                 SetClientScreenArea(0, 0, 0, screen.height - CELLH);
  206.         }
  207. }
  208.  
  209. byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
  210. {
  211.         attached.add(key_name);
  212.         return true;
  213. }
  214.  
  215. void GetAttachedItems()
  216. {
  217.         attached.drop();
  218.         ini_enum_keys stdcall ("/sys/settings/appicons.ini", "attached", #draw_icons_from_section);
  219. }
  220. //===================================================//
  221. //                                                   //
  222. //                      EVENTS                       //
  223. //                                                   //
  224. //===================================================//
  225.  
  226. //If we clicked on current active process then minimize it
  227. //else set active
  228. void EventSetActiveProcess(dword i)
  229. {
  230.         GetProcessInfo(#Process, proc_list[i+list.first]);
  231.         Process.slot = GetProcessSlot(Process.ID);
  232.         if (Process.ID) ActivateWindow(Process.slot);
  233.         if (current_process_id == Process.ID) && (Process.status_window!=2) {
  234.                 MinimizeWindow();
  235.                 //TODO: make another window active
  236.         }
  237.         DrawProcessList();
  238. }
  239.  
  240.  
  241. stop: