-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.c
106 lines (96 loc) · 2.39 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "process.h"
#include "data.h"
#include <stdlib.h>
struct node* pausedProcesses[10];
struct node* pausedProcessesEnd[10];
int getGroupNumber()
{
int i;
for(i = 0x30; i != 0x30+10; ++i){
if(GetKeyState(i) < 0)
return i-0x30;
}
return -1;
}
int isInGroup(struct processData* pData)
{
int group;
for(group = 0; group != 10; ++group){
struct node* ptr;
for(ptr = pausedProcesses[group]; ptr != pausedProcessesEnd[group]; ptr = ptr->next){
if(ptr->data->pid == pData->pid){
return 1;
}
}
}
return 0;
}
void addGroup(int group, struct processData* pData)
{
if(isInGroup(pData)){
free(pData);
return;
}
pausedProcessesEnd[group]->next = malloc(sizeof(struct node));
pausedProcessesEnd[group]->data = pData;
pausedProcessesEnd[group] = pausedProcessesEnd[group]->next;
}
void resumeGroup(int group)
{
struct node* ptr;
for(ptr = pausedProcesses[group]; ptr != pausedProcessesEnd[group]; ptr = ptr->next){
resumeProcess(ptr->data);
}
}
void pauseGroup(int group)
{
struct node* ptr;
for(ptr = pausedProcesses[group]; ptr != pausedProcessesEnd[group]; ptr = ptr->next){
pauseProcess(ptr->data);
}
}
void addGroupPaused(int group, struct processData* pData)
{
pauseProcess(pData);
addGroup(group, pData);
}
void initGroups()
{
int i;
for(i = 0; i != 10; ++i){
pausedProcesses[i] = malloc(sizeof(struct node));
pausedProcesses[i]->next = 0;
pausedProcessesEnd[i] = pausedProcesses[i];
}
}
int main()
{
initGroups();
while(1){
Sleep(50);
int group = getGroupNumber();
if(group == -1){
continue;
}
if(GetKeyState(VK_SHIFT) < 0){
struct processData *pData = pDataByWindow();
if(GetKeyState(VK_LCONTROL) < 0 || GetKeyState(VK_RCONTROL) < 0){
addGroupPaused(group, pData);
continue;
}
addGroup(group,pData);
continue;
}
if(GetKeyState(VK_LCONTROL) < 0 || GetKeyState(VK_RCONTROL) < 0){
if(GetKeyState(VK_SHIFT) < 0){
continue;
}
pauseGroup(group);
continue;
}
if(GetKeyState(VK_LMENU) < 0){
resumeGroup(group);
continue;
}
}
}